1 | <?php |
||
16 | class EqualOperatorSniff extends AbstractSniff |
||
17 | { |
||
18 | /** |
||
19 | * Is this sniff allowed to fix? |
||
20 | * |
||
21 | * @var bool $isFixing |
||
22 | */ |
||
23 | private $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 | * @param File $phpcsFile |
||
|
|||
45 | * @param int $stackPtr |
||
46 | * |
||
47 | * @return void |
||
48 | */ |
||
49 | private function findToken(): void |
||
63 | |||
64 | /** |
||
65 | * Processes the token. |
||
66 | * |
||
67 | * @param File $phpcsFile |
||
68 | * @param int $stackPtr |
||
69 | * |
||
70 | * @return void |
||
71 | */ |
||
72 | protected function processToken(): void |
||
76 | |||
77 | /** |
||
78 | * Registers the tokens that this sniff wants to listen for. |
||
79 | * |
||
80 | * An example return value for a sniff that wants to listen for whitespace |
||
81 | * and any comments would be: |
||
82 | * |
||
83 | * <code> |
||
84 | * return array( |
||
85 | * T_WHITESPACE, |
||
86 | * T_DOC_COMMENT, |
||
87 | * T_COMMENT, |
||
88 | * ); |
||
89 | * </code> |
||
90 | * |
||
91 | * @return int[] |
||
92 | * @see Tokens.php |
||
93 | */ |
||
94 | public function register(): array |
||
98 | |||
99 | /** |
||
100 | * Replace token with the T_IS_IDENTIAL token. |
||
101 | * |
||
102 | * @param File $phpcsFile |
||
103 | * @param int $stackPtr |
||
104 | * |
||
105 | * @return void |
||
106 | */ |
||
107 | private function replaceToken(File $phpcsFile, int $stackPtr): void |
||
113 | } |
||
114 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.