23
23
class UnusedFunctionParameterSniff implements Sniff
24
24
{
25
25
26
+ /**
27
+ * The list of class type hints which will be ignored.
28
+ *
29
+ * @var array
30
+ */
31
+ public $ ignoreTypeHints = [];
32
+
26
33
27
34
/**
28
35
* Returns an array of tokens this test wants to listen for.
@@ -191,6 +198,10 @@ public function process(File $phpcsFile, $stackPtr)
191
198
// If there is only one parameter and it is unused, no need for additional errorcode toggling logic.
192
199
if ($ methodParamsCount === 1 ) {
193
200
foreach ($ params as $ paramName => $ position ) {
201
+ if (in_array ($ methodParams [0 ]['type_hint ' ], $ this ->ignoreTypeHints , true ) === true ) {
202
+ continue ;
203
+ }
204
+
194
205
$ data = [$ paramName ];
195
206
$ phpcsFile ->addWarning ($ error , $ position , $ errorCode , $ data );
196
207
}
@@ -207,6 +218,7 @@ public function process(File $phpcsFile, $stackPtr)
207
218
$ errorInfo [$ methodParams [$ i ]['name ' ]] = [
208
219
'position ' => $ params [$ methodParams [$ i ]['name ' ]],
209
220
'errorcode ' => $ errorCode .'BeforeLastUsed ' ,
221
+ 'typehint ' => $ methodParams [$ i ]['type_hint ' ],
210
222
];
211
223
}
212
224
} else {
@@ -216,14 +228,19 @@ public function process(File $phpcsFile, $stackPtr)
216
228
$ errorInfo [$ methodParams [$ i ]['name ' ]] = [
217
229
'position ' => $ params [$ methodParams [$ i ]['name ' ]],
218
230
'errorcode ' => $ errorCode .'AfterLastUsed ' ,
231
+ 'typehint ' => $ methodParams [$ i ]['type_hint ' ],
219
232
];
220
233
}
221
234
}
222
- }
235
+ }//end for
223
236
224
237
if (count ($ errorInfo ) > 0 ) {
225
238
$ errorInfo = array_reverse ($ errorInfo );
226
239
foreach ($ errorInfo as $ paramName => $ info ) {
240
+ if (in_array ($ info ['typehint ' ], $ this ->ignoreTypeHints , true ) === true ) {
241
+ continue ;
242
+ }
243
+
227
244
$ data = [$ paramName ];
228
245
$ phpcsFile ->addWarning ($ error , $ info ['position ' ], $ info ['errorcode ' ], $ data );
229
246
}
0 commit comments