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