OrganizationId::getLegalForm()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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