Total Complexity | 4 |
Total Lines | 33 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
13 | class ApiVersion |
||
14 | { |
||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $apiVersion; |
||
19 | |||
20 | /** |
||
21 | * @param array $values |
||
22 | * |
||
23 | * @throws \InvalidArgumentException When no API version provided or wrong format |
||
24 | */ |
||
25 | 23 | public function __construct(array $values) |
|
26 | { |
||
27 | 23 | if (!isset($values['value'])) { |
|
28 | 1 | throw new \InvalidArgumentException('No API version provided'); |
|
29 | } |
||
30 | |||
31 | 22 | $stringifiedValue = (string) $values['value']; |
|
32 | |||
33 | 22 | if (!preg_match('/^\d{1,}(?:\.\d{1,}){0,1}$/', $stringifiedValue)) { |
|
34 | 4 | throw new \InvalidArgumentException('API version must have X or X.X format'); |
|
35 | } |
||
36 | |||
37 | 18 | $this->apiVersion = $stringifiedValue; |
|
38 | 18 | } |
|
39 | |||
40 | /** |
||
41 | * @return string |
||
42 | */ |
||
43 | 13 | public function getApiVersion(): string |
|
46 | } |
||
47 | } |
||
48 |