-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathOrganizationId.php
More file actions
37 lines (29 loc) · 956 Bytes
/
OrganizationId.php
File metadata and controls
37 lines (29 loc) · 956 Bytes
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
<?php
declare(strict_types=1);
namespace byrokrat\id;
use byrokrat\id\Helper\BasicIdTrait;
use byrokrat\id\Helper\Modulo10;
use byrokrat\id\Helper\NumberParser;
use byrokrat\id\Exception\UnableToCreateIdException;
class OrganizationId implements IdInterface
{
use BasicIdTrait;
/**
* Regular expression describing id structure
*/
private const PATTERN = '/^(?:00)?(\d{2}[2-9]\d{3})[-]?(\d{3})(\d)$/';
/**
* Create organizational identity number
*
* @throws UnableToCreateIdException On failure to create id
*/
public function __construct(string $number)
{
list($this->serialPre, $this->serialPost, $this->checkDigit) = NumberParser::parse(self::PATTERN, $number);
Modulo10::validateCheckDigit($this);
}
public function getLegalForm(): string
{
return LegalForms::LEGAL_FORM_MAP[$this->getSerialPreDelimiter()[0]] ?? LegalForms::LEGAL_FORM_UNDEFINED;
}
}