Total Complexity | 10 |
Total Lines | 60 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
13 | class ResponseSchemaValidator |
||
14 | { |
||
15 | /** |
||
16 | * @var array [string format => [int responseCode => string pathToSchemaFile]] |
||
17 | */ |
||
18 | protected $schemas = []; |
||
19 | |||
20 | /** |
||
21 | * @param array $data [string format => [int responseCode => string pathToSchemaFile]] |
||
22 | * |
||
23 | * @throws \InvalidArgumentException |
||
24 | */ |
||
25 | 10 | public function __construct(array $data) |
|
26 | { |
||
27 | 10 | if (empty($data)) { |
|
28 | 1 | throw new \InvalidArgumentException('Empty schemas provided'); |
|
29 | } |
||
30 | |||
31 | 9 | foreach ($data as $format => $schemas) { |
|
32 | 9 | if (!\is_string($format)) { |
|
33 | 1 | throw new \InvalidArgumentException($format.' is not a string'); |
|
34 | } |
||
35 | |||
36 | 8 | if (!\is_array($schemas)) { |
|
37 | 1 | throw new \InvalidArgumentException($schemas.' is not an array'); |
|
38 | } |
||
39 | |||
40 | 7 | $this->loadFormatSchemas($format, $schemas); |
|
41 | } |
||
42 | 5 | } |
|
43 | |||
44 | /** |
||
45 | * @return array |
||
46 | */ |
||
47 | 20 | public function getSchemas(): array |
|
48 | { |
||
49 | 20 | return $this->schemas; |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * @param string $format |
||
54 | * @param array $schemas |
||
55 | * |
||
56 | * @throws \InvalidArgumentException |
||
57 | */ |
||
58 | 7 | protected function loadFormatSchemas(string $format, array $schemas): void |
|
73 | } |
||
74 | 5 | } |
|
75 | } |
||
76 |