Conditions | 6 |
Paths | 5 |
Total Lines | 23 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 6 |
Changes | 0 |
1 | <?php |
||
19 | 27 | public function check(Resource $resource) |
|
20 | { |
||
21 | 27 | $allowed = array_merge( |
|
22 | 27 | $resource->allowed(), |
|
23 | 27 | $resource->mandatory() |
|
24 | ); |
||
25 | |||
26 | 27 | foreach ($resource->properties() as $key => $value) { |
|
27 | 19 | if (!in_array($key, $allowed)) { |
|
28 | 3 | foreach ($allowed as $kk => $vv) { |
|
29 | 3 | if (!is_numeric($kk) && $resource->hasProperty($vv['when']['property'])) { |
|
30 | 2 | return; |
|
31 | } |
||
32 | } |
||
33 | |||
34 | 1 | throw new \Sensorario\Resources\Exceptions\NotAllowedKeyException( |
|
35 | 1 | "Key `" . get_class($resource) |
|
36 | 1 | . "::\$$key` with value `" . $value |
|
37 | 1 | . "` is not allowed" |
|
38 | ); |
||
39 | } |
||
40 | } |
||
41 | 24 | } |
|
42 | } |
||
43 |