1 | <?php |
||
20 | final class YodaConditionSniff implements PHP_CodeSniffer_Sniff |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | const MESSAGE_ERROR = 'Yoda condition should not be used; switch expression order'; |
||
27 | |||
28 | /** |
||
29 | * @var int |
||
30 | */ |
||
31 | private $position; |
||
32 | |||
33 | /** |
||
34 | * @var PHP_CodeSniffer_File |
||
35 | */ |
||
36 | private $file; |
||
37 | |||
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | 1 | public function register() |
|
55 | |||
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | 1 | public function process(PHP_CodeSniffer_File $file, $position) |
|
73 | |||
74 | |||
75 | /** |
||
76 | * @return array|bool |
||
77 | */ |
||
78 | 1 | private function getPreviousNonEmptyToken() |
|
87 | |||
88 | |||
89 | 1 | private function isExpressionToken(array $token) : bool |
|
96 | |||
97 | } |
||
98 |
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.