1 | <?php |
||
16 | class EqualOperatorSniff extends AbstractSniff |
||
17 | { |
||
18 | /** |
||
19 | * Is this sniff allowed to fix? |
||
20 | * |
||
21 | * @var bool $isFixing |
||
22 | */ |
||
23 | public $isFixing = false; |
||
24 | |||
25 | /** |
||
26 | * Code when an equal operator was found. |
||
27 | * |
||
28 | * @var string CODE_EQUAL_OPERATOR_FOUND |
||
29 | */ |
||
30 | public const CODE_EQUAL_OPERATOR_FOUND = 'EqualOperatorFound'; |
||
31 | |||
32 | /** |
||
33 | * Warning when an equal operator was found. |
||
34 | * |
||
35 | * @var string WARNING_EQUAL_OPERATOR_FOUND |
||
36 | */ |
||
37 | private const WARNING_EQUAL_OPERATOR_FOUND = ' |
||
38 | Please check if you could use the "Identical" operator (===). |
||
39 | '; |
||
40 | |||
41 | /** |
||
42 | * Find the T_IS_EQUAL token and add a warning. |
||
43 | * |
||
44 | * @return void |
||
45 | */ |
||
46 | private function findToken(): void |
||
60 | |||
61 | /** |
||
62 | * Processes the token. |
||
63 | * |
||
64 | * @return void |
||
65 | */ |
||
66 | protected function processToken(): void |
||
70 | |||
71 | /** |
||
72 | * Registers the tokens that this sniff wants to listen for. |
||
73 | * |
||
74 | * An example return value for a sniff that wants to listen for whitespace |
||
75 | * and any comments would be: |
||
76 | * |
||
77 | * <code> |
||
78 | * return array( |
||
79 | * T_WHITESPACE, |
||
80 | * T_DOC_COMMENT, |
||
81 | * T_COMMENT, |
||
82 | * ); |
||
83 | * </code> |
||
84 | * |
||
85 | * @return int[] |
||
86 | * @see Tokens.php |
||
87 | */ |
||
88 | public function register(): array |
||
92 | |||
93 | /** |
||
94 | * Replace token with the T_IS_IDENTIAL token. |
||
95 | * |
||
96 | * @param File $phpcsFile |
||
97 | * @param int $stackPtr |
||
98 | * |
||
99 | * @return void |
||
100 | */ |
||
101 | private function replaceToken(File $phpcsFile, int $stackPtr): void |
||
107 | } |
||
108 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: