Total Complexity | 5 |
Total Lines | 23 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | class VatIdRule implements Rule |
||
9 | { |
||
10 | public function __construct(private string $countryCode) |
||
11 | { |
||
12 | } |
||
13 | |||
14 | public function passes($attribute, $vatId): bool |
||
15 | { |
||
16 | // can't validate without country code |
||
17 | if (!$this->countryCode) { |
||
18 | return true; |
||
19 | } |
||
20 | |||
21 | if ($this->countryCode !== 'CH') { |
||
22 | $vatId = preg_replace('/[^0-9A-Za-z]/', '', $vatId); |
||
23 | } |
||
24 | |||
25 | return (new Validator)->isValid($this->countryCode . $vatId); |
||
26 | } |
||
27 | |||
28 | public function message() |
||
31 | } |
||
32 | } |
||
33 |