1 | <?php |
||
27 | class AlphabeticallySortedUsesSniff extends AbstractSniff |
||
28 | { |
||
29 | /** |
||
30 | * You MUST provide your imports in alphabetically order, PSR-12 compatible. |
||
31 | */ |
||
32 | public const CODE_INCORRECT_ORDER = 'IncorrectlyOrderedUses'; |
||
33 | |||
34 | /** |
||
35 | * The found use statements. |
||
36 | * |
||
37 | * @var UseStatement[] |
||
38 | */ |
||
39 | private $useStatements; |
||
40 | |||
41 | /** |
||
42 | * Returns true if we have use statements. |
||
43 | * |
||
44 | * @return bool |
||
45 | */ |
||
46 | protected function areRequirementsMet(): bool |
||
53 | |||
54 | /** |
||
55 | * Will removing a compare marker for the given use statements. |
||
56 | * |
||
57 | * @param UseStatement $prevStatement |
||
58 | * @param UseStatement $nextStatement |
||
59 | * |
||
60 | * @return int 1 <=> -1 To move statements in a direction. |
||
61 | */ |
||
62 | private function compareUseStatements(UseStatement $prevStatement, UseStatement $nextStatement): int |
||
79 | |||
80 | /** |
||
81 | * Compares the given use statements by their string content. |
||
82 | * |
||
83 | * @SuppressWarnings(PHPMD.UnusedPrivateMethod) |
||
84 | * |
||
85 | * @param UseStatement $prevStatement |
||
86 | * @param UseStatement $nextStatement |
||
87 | * |
||
88 | * @return int|null 1 <=> -1 To move statements in a direction. |
||
89 | */ |
||
90 | private function compareUseStatementsByContent(UseStatement $prevStatement, UseStatement $nextStatement): ?int |
||
110 | |||
111 | /** |
||
112 | * The shorted usage comes at top. |
||
113 | * |
||
114 | * @SuppressWarnings(PHPMD.UnusedPrivateMethod) |
||
115 | * |
||
116 | * @param UseStatement $prevStatement |
||
117 | * @param UseStatement $nextStatement |
||
118 | * |
||
119 | * @return int 1 <=> -1 To move statements in a direction. |
||
120 | */ |
||
121 | private function compareUseStatementsByNamespaceCount( |
||
130 | |||
131 | /** |
||
132 | * Classes to the top, functions next, constants last. |
||
133 | * |
||
134 | * @SuppressWarnings(PHPMD.UnusedPrivateMethod) |
||
135 | * |
||
136 | * @param UseStatement $prevStatement |
||
137 | * @param UseStatement $nextStatement |
||
138 | * |
||
139 | * @return int|null 1 <=> -1 To move statements in a direction. |
||
140 | */ |
||
141 | private function compareUseStatementsByType(UseStatement $prevStatement, UseStatement $nextStatement): ?int |
||
159 | |||
160 | /** |
||
161 | * Sorts the uses correctly and saves them in the file. |
||
162 | * |
||
163 | * @param CodeWarning $error |
||
164 | * |
||
165 | * @return void |
||
166 | */ |
||
167 | protected function fixDefaultProblem(CodeWarning $error): void |
||
187 | |||
188 | /** |
||
189 | * Returns the new statements as a string for fixing. |
||
190 | * |
||
191 | * @return string |
||
192 | */ |
||
193 | private function getNewUseStatements(): string |
||
227 | |||
228 | /** |
||
229 | * Checks if the uses are in the correct order. |
||
230 | * |
||
231 | * @throws CodeError |
||
232 | * |
||
233 | * @return void |
||
234 | */ |
||
235 | protected function processToken(): void |
||
257 | |||
258 | /** |
||
259 | * Registers the tokens that this sniff wants to listen for. |
||
260 | * |
||
261 | * An example return value for a sniff that wants to listen for whitespace |
||
262 | * and any comments would be: |
||
263 | * |
||
264 | * <code> |
||
265 | * return array( |
||
266 | * T_WHITESPACE, |
||
267 | * T_DOC_COMMENT, |
||
268 | * T_COMMENT, |
||
269 | * ); |
||
270 | * </code> |
||
271 | * |
||
272 | * @return int[] |
||
273 | */ |
||
274 | public function register(): array |
||
278 | |||
279 | /** |
||
280 | * Removes the lines of the old statements. |
||
281 | * |
||
282 | * @param UseStatement $firstUseStatement |
||
283 | * |
||
284 | * @return void |
||
285 | */ |
||
286 | private function removeOldUseStatements(UseStatement $firstUseStatement): void |
||
296 | |||
297 | /** |
||
298 | * Saves the use-property by the compare function. |
||
299 | * |
||
300 | * @return void |
||
301 | */ |
||
302 | private function sortUseStatements(): void |
||
308 | } |
||
309 |
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: