OrganizationId   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 26
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getLegalForm() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace byrokrat\id;
6
7
use byrokrat\id\Helper\BasicIdTrait;
8
use byrokrat\id\Helper\Modulo10;
9
use byrokrat\id\Helper\NumberParser;
10
use byrokrat\id\Exception\UnableToCreateIdException;
11
12
class OrganizationId implements IdInterface
13
{
14
    use BasicIdTrait;
15
16
    /**
17
     * Regular expression describing id structure
18
     */
19
    private const PATTERN = '/^(?:00)?(\d{2}[2-9]\d{3})[-]?(\d{3})(\d)$/';
20
21
    /**
22
     * Create organizational identity number
23
     *
24
     * @throws UnableToCreateIdException On failure to create id
25
     */
26
    public function __construct(string $number)
27
    {
28
        list($this->serialPre, $this->serialPost, $this->checkDigit) = NumberParser::parse(self::PATTERN, $number);
29
30
        Modulo10::validateCheckDigit($this);
31
    }
32
33
    public function getLegalForm(): string
34
    {
35
        return LegalForms::LEGAL_FORM_MAP[$this->getSerialPreDelimiter()[0]] ?? LegalForms::LEGAL_FORM_UNDEFINED;
36
    }
37
}
38