Total Complexity | 5 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | class PostalCodeNl extends ScalarType |
||
10 | { |
||
11 | private const PATTERN = '/^\d{4}[a-zA-Z]{2}$/'; |
||
12 | |||
13 | /** @var string */ |
||
14 | public $name = 'PostalCodeNl'; |
||
15 | |||
16 | /** @var string */ |
||
17 | public $description = 'A valid postalcode for The Netherlands with pattern [1234aa]. Example: 1234AA.'; |
||
18 | |||
19 | /** |
||
20 | * @inheritDoc |
||
21 | */ |
||
22 | public function serialize($value) |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * @inheritDoc |
||
29 | */ |
||
30 | public function parseValue($value) |
||
31 | { |
||
32 | if (! \preg_match(self::PATTERN, $value)) { |
||
33 | throw new Error(sprintf('Input error: Expected valid postal code with pattern [1234aa], got: [%s]', $value)); |
||
34 | } |
||
35 | |||
36 | return $value; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * @inheritDoc |
||
41 | */ |
||
42 | public function parseLiteral($valueNode, array $variables = null) |
||
49 | } |
||
50 | } |
||
51 |