-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFakeId.php
More file actions
57 lines (46 loc) · 1.66 KB
/
FakeId.php
File metadata and controls
57 lines (46 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
declare(strict_types=1);
namespace byrokrat\id;
use byrokrat\id\Helper\NumberParser;
use byrokrat\id\Exception\UnableToCreateIdException;
class FakeId extends PersonalId
{
/**
* Regular expression describing id structure
*/
protected const PATTERN = '/^((?:\d\d)?)(\d{6})([-+]?)(xx[0-9xfmo])(x)$/i';
/**
* Create fake personal identity number
*
* Fake ids replace serial number post delimiter with xxxx. If sex should be
* encoded xxFx, xxMx or xxOx can be used, denoting Female, Male or Other.
*
* @param string $raw The raw id to parse
* @param \DateTimeInterface $atDate Optional date when parsing takes place, defaults to today
* @throws UnableToCreateIdException On failure to create id
*/
public function __construct(string $raw, \DateTimeInterface $atDate = null)
{
list($century, $datestr, $delimiter, $serialPost, $check) = NumberParser::parse(self::PATTERN, $raw);
parent::__construct($century . $datestr . $delimiter . '0000', $atDate);
$this->serialPost = $serialPost;
$this->checkDigit = $check;
}
public function getSex(): string
{
foreach ([Sexes::SEX_FEMALE, Sexes::SEX_MALE, Sexes::SEX_OTHER, Sexes::SEX_UNDEFINED] as $sexIdentifier) {
if (strcasecmp($sexIdentifier, $this->getSerialPostDelimiter()[2]) === 0) {
return $sexIdentifier;
}
}
return parent::getSex();
}
public function getBirthCounty(): string
{
return Counties::COUNTY_UNDEFINED;
}
protected function validateCheckDigit(): void
{
// Fake ids always have valid check digits
}
}