1 | <?php |
||
18 | final class YodaConditionSniff implements PHP_CodeSniffer_Sniff |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | const MESSAGE_ERROR = 'Yoda condition should not be used; switch expression order'; |
||
25 | |||
26 | /** |
||
27 | * @var int |
||
28 | */ |
||
29 | private $position; |
||
30 | |||
31 | /** |
||
32 | * @var PHP_CodeSniffer_File |
||
33 | */ |
||
34 | private $file; |
||
35 | |||
36 | |||
37 | /** |
||
38 | * {@inheritdoc} |
||
39 | */ |
||
40 | 1 | public function register() |
|
53 | |||
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | 1 | public function process(PHP_CodeSniffer_File $file, $position) |
|
71 | |||
72 | |||
73 | /** |
||
74 | * @return array|bool |
||
75 | */ |
||
76 | 1 | private function getPreviousNonEmptyToken() |
|
85 | |||
86 | |||
87 | /** |
||
88 | * @return bool |
||
89 | */ |
||
90 | 1 | private function isExpressionToken(array $token) |
|
97 | |||
98 | } |
||
99 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.