Total Complexity | 5 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 17 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
10 | class TaxNumberFormatter implements Formatter |
||
11 | { |
||
12 | /** |
||
13 | * @param string|null $tax_number |
||
14 | * @param string|null $country |
||
15 | */ |
||
16 | 17 | public function __construct( |
|
17 | public ?string $tax_number = null, |
||
18 | public ?string $country = null |
||
19 | ) { |
||
20 | 17 | $filteredTaxNumber = preg_replace('/[^\d\w]/', '', (string) $this->tax_number); |
|
21 | |||
22 | 17 | $this->tax_number = Str::upper($filteredTaxNumber); |
|
23 | 17 | $this->country = Str::upper($this->country); |
|
24 | } |
||
25 | |||
26 | /** |
||
27 | * Format the Tax Number. |
||
28 | * |
||
29 | * @return string|null |
||
30 | */ |
||
31 | 17 | public function format(): ?string |
|
32 | { |
||
33 | 17 | return ! blank($this->country) |
|
34 | 13 | ? $this->getFullTaxNumber() |
|
35 | 17 | : $this->tax_number; |
|
36 | } |
||
37 | |||
38 | /** |
||
39 | * @return string |
||
40 | */ |
||
41 | 13 | private function getFullTaxNumber(): string |
|
50 | } |
||
51 | } |
||
52 |