Conditions | 5 |
Paths | 4 |
Total Lines | 16 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
15 | public function setValue(string $value): void |
||
16 | { |
||
17 | $value = StringUtils::trimSpacesWisely($value); |
||
18 | $changedValue = StringUtils::removeNonWordCharacters($value); |
||
|
|||
19 | $characters = StringUtils::countCharacters($changedValue); |
||
20 | |||
21 | if ($characters == 4) { |
||
22 | $value = '0' . $value; |
||
23 | $characters++; |
||
24 | } |
||
25 | |||
26 | if (empty($value) || $characters != 5 && $characters != 9) { |
||
27 | throw new \InvalidArgumentException(sprintf('The value "%s" is not a valid postal code.', $value)); |
||
28 | } |
||
29 | |||
30 | parent::setValue($value); |
||
31 | } |
||
33 |