1 | <?php |
||
17 | final class AllowedProperties implements Validator |
||
18 | { |
||
19 | private $resource; |
||
20 | |||
21 | private $allowed; |
||
22 | |||
23 | 27 | public function check(Resource $resource) |
|
24 | { |
||
25 | 27 | $this->resource = $resource; |
|
26 | 27 | $this->buildAllowedProperties(); |
|
27 | 27 | if (!$this->checkShouldBeSkipped()) { |
|
|
|||
28 | 25 | $this->ensurePropertyIsAllowed(); |
|
29 | } |
||
30 | 26 | } |
|
31 | |||
32 | 27 | private function buildAllowedProperties() |
|
39 | |||
40 | 27 | private function checkShouldBeSkipped() |
|
41 | { |
||
42 | 27 | foreach ($this->allowed as $kk => $vv) { |
|
43 | 25 | if ($this->mustSkip($kk, $vv)) { |
|
44 | 2 | return true; |
|
45 | } |
||
46 | } |
||
47 | 25 | } |
|
48 | |||
49 | 25 | public function ensurePropertyIsAllowed() |
|
59 | |||
60 | 25 | public function mustSkip($key, $value) |
|
66 | } |
||
67 |
If an expression can have both
false
, andnull
as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.