1 | <?php |
||
24 | class FluentSetterSniff extends MethodScopeSniff |
||
25 | { |
||
26 | /** |
||
27 | * Code when the method does not return $this. |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | public const CODE_MUST_RETURN_THIS = 'MustReturnThis'; |
||
32 | |||
33 | /** |
||
34 | * Code when no return statement is found. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | public const CODE_NO_RETURN_FOUND = 'NoReturnFound'; |
||
39 | |||
40 | /** |
||
41 | * Error message when the method does not return $this. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | private const ERROR_MUST_RETURN_THIS = 'The method "%s" must return $this'; |
||
46 | |||
47 | /** |
||
48 | * Error message when no return statement is found. |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | private const ERROR_NO_RETURN_FOUND = 'Method "%s" has no return statement'; |
||
53 | |||
54 | /** |
||
55 | * Specifies how an identation looks like. |
||
56 | * |
||
57 | * @var string |
||
58 | */ |
||
59 | public $identation = ' '; |
||
60 | |||
61 | /** |
||
62 | * Registers an error if an empty return (return null; or return;) is given. |
||
63 | * |
||
64 | * @param File $file The sniffed file. |
||
65 | * @param int $functionPos The position of the function. |
||
66 | * @param int $returnPos The position of the return call. |
||
67 | * @param string $methodIdent The ident for the method to given in an error. |
||
68 | * |
||
69 | * @return void |
||
70 | */ |
||
71 | 4 | private function checkAndRegisterEmptyReturnErrors( |
|
92 | |||
93 | 4 | /** |
|
94 | 1 | * Checks if there are fluent setter errors and registers errors if needed. |
|
95 | * |
||
96 | * @param File $phpcsFile The file for this sniff. |
||
97 | 4 | * @param int $functionPos The position of the used token. |
|
98 | 4 | * @param int $classPos The position of the class. |
|
99 | * |
||
100 | 4 | * @return void |
|
101 | 4 | */ |
|
102 | 4 | private function checkForFluentSetterErrors(File $phpcsFile, int $functionPos, int $classPos): void |
|
130 | 1 | ||
131 | 1 | /** |
|
132 | 1 | * Get the sniff name. |
|
133 | * |
||
134 | 1 | * @param string $sniffName If there is an optional sniff name. |
|
135 | * |
||
136 | * @return string Returns the special sniff name in the code sniffer context. |
||
137 | 3 | */ |
|
138 | private function getSniffName(string $sniffName = ''): string |
||
152 | |||
153 | 3 | /** |
|
154 | * Processes the tokens that this test is listening for. |
||
155 | * |
||
156 | * @param File $file The file where this token was found. |
||
157 | * @param int $functionPos The position in the stack where this token was found. |
||
158 | * @param int $classPos The position in the tokens array that opened the scope that this test is listening for. |
||
159 | * |
||
160 | * @return void |
||
161 | */ |
||
162 | protected function processTokenWithinScope( |
||
177 | |||
178 | /** |
||
179 | * Checks if the given method name relates to a setter function of a property. |
||
180 | * |
||
181 | 1 | * @param int $classPosition The position of the class token. |
|
182 | * @param File $file The file of the sniff. |
||
183 | 1 | * @param int $methodPosition The position of the method token. |
|
184 | 1 | * |
|
185 | * @return bool Indicator if the given method is a setter function |
||
186 | 1 | */ |
|
187 | private function checkIfSetterFunction(int $classPosition, File $file, int $methodPosition): bool |
||
205 | 1 | ||
206 | /** |
||
207 | 1 | * Fixes if no return statement is found. |
|
208 | 1 | * |
|
209 | * @param File $phpcsFile The php cs file |
||
210 | * @param int $closingBracePtr Pointer to the closing curly brace of the function |
||
211 | 1 | * |
|
212 | 1 | * @return void |
|
213 | 1 | */ |
|
214 | 1 | private function fixNoReturnFound(File $phpcsFile, int $closingBracePtr) |
|
227 | |||
228 | /** |
||
229 | * Fixes the return value of a function to $this. |
||
230 | * |
||
231 | * @param File $phpcsFile The php cs file |
||
232 | * @param int $returnPtr Pointer to the return token |
||
233 | * |
||
234 | * @return void |
||
235 | */ |
||
236 | private function fixMustReturnThis(File $phpcsFile, $returnPtr) |
||
251 | } |
||
252 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: