Completed
Push — master ( a004d3...9bce71 )
by Hannes
02:34
created

FakeId   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 39
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getSex() 0 4 2
A getBirthCounty() 0 4 1
A validateCheckDigit() 0 3 1
1
<?php
2
3
namespace byrokrat\id;
4
5
/**
6
 * Fake personal identity numbers
7
 *
8
 * Fake ids replace serial number post delimiter with xxxx. If sex should be
9
 * encoded xx1x or xx2x can be used.
10
 */
11
class FakeId extends PersonalId
12
{
13
    /**
14
     * Regular expression describing id structure
15
     */
16
    const PATTERN = '/^((?:\d\d)?)(\d{6})([-+]?)(xx[12x])(x)$/i';
17
18
    /**
19
     * Fake personal identity numbers
20
     *
21
     * {@inheritdoc}
22
     *
23
     * @param string $number
24
     */
25 34
    public function __construct($number)
26
    {
27 34
        list(, $century, $datestr, $delimiter, $serialPost, $check) = $this->parseNumber(self::PATTERN, $number);
28 12
        parent::__construct($century . $datestr . $delimiter . '0000');
29 12
        $this->serialPost = $serialPost;
30 12
        $this->checkDigit = $check;
31 12
    }
32
33 1
    public function getSex()
34
    {
35 1
        return is_numeric($this->getSerialPostDelimiter()[2]) ? parent::getSex() : self::SEX_UNDEFINED;
36
    }
37
38 1
    public function getBirthCounty()
39
    {
40 1
        return IdInterface::COUNTY_UNDEFINED;
41
    }
42
43
    /**
44
     * Fake ids always have valid check digits
45
     */
46 12
    protected function validateCheckDigit()
47
    {
48 12
    }
49
}
50