Total Complexity | 9 |
Total Lines | 37 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
17 | trait Validator |
||
18 | { |
||
19 | /** |
||
20 | * @param $decodedRule |
||
21 | * @param $type |
||
22 | * |
||
23 | * @return bool |
||
24 | * @throws Exception |
||
25 | */ |
||
26 | private function validate($decodedRule, $type): bool |
||
27 | { |
||
28 | switch ($type) { |
||
29 | case 'single': |
||
30 | if (isset($decodedRule['date'])) { |
||
31 | return $decodedRule; |
||
32 | } |
||
33 | break; |
||
34 | case 'period': |
||
35 | if (isset($decodedRule['from']) && isset($decodedRule['to'])) { |
||
36 | return true; |
||
37 | } |
||
38 | break; |
||
39 | case 'recurrent_day': |
||
40 | if (isset($decodedRule['dayOfWeek'])) { |
||
41 | return true; |
||
42 | } |
||
43 | break; |
||
44 | } |
||
45 | $this->throwException(); |
||
|
|||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @throws Exception |
||
50 | */ |
||
51 | private function throwException() |
||
54 | } |
||
55 | } |
||
56 |
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: