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