2323class UnusedFunctionParameterSniff implements Sniff
2424{
2525
26+ /**
27+ * The list of class type hints which will be ignored.
28+ *
29+ * @var array
30+ */
31+ public $ ignoreTypeHints = [];
32+
2633
2734 /**
2835 * Returns an array of tokens this test wants to listen for.
@@ -191,6 +198,10 @@ public function process(File $phpcsFile, $stackPtr)
191198 // If there is only one parameter and it is unused, no need for additional errorcode toggling logic.
192199 if ($ methodParamsCount === 1 ) {
193200 foreach ($ params as $ paramName => $ position ) {
201+ if (in_array ($ methodParams [0 ]['type_hint ' ], $ this ->ignoreTypeHints , true ) === true ) {
202+ continue ;
203+ }
204+
194205 $ data = [$ paramName ];
195206 $ phpcsFile ->addWarning ($ error , $ position , $ errorCode , $ data );
196207 }
@@ -207,6 +218,7 @@ public function process(File $phpcsFile, $stackPtr)
207218 $ errorInfo [$ methodParams [$ i ]['name ' ]] = [
208219 'position ' => $ params [$ methodParams [$ i ]['name ' ]],
209220 'errorcode ' => $ errorCode .'BeforeLastUsed ' ,
221+ 'typehint ' => $ methodParams [$ i ]['type_hint ' ],
210222 ];
211223 }
212224 } else {
@@ -216,14 +228,19 @@ public function process(File $phpcsFile, $stackPtr)
216228 $ errorInfo [$ methodParams [$ i ]['name ' ]] = [
217229 'position ' => $ params [$ methodParams [$ i ]['name ' ]],
218230 'errorcode ' => $ errorCode .'AfterLastUsed ' ,
231+ 'typehint ' => $ methodParams [$ i ]['type_hint ' ],
219232 ];
220233 }
221234 }
222- }
235+ }//end for
223236
224237 if (count ($ errorInfo ) > 0 ) {
225238 $ errorInfo = array_reverse ($ errorInfo );
226239 foreach ($ errorInfo as $ paramName => $ info ) {
240+ if (in_array ($ info ['typehint ' ], $ this ->ignoreTypeHints , true ) === true ) {
241+ continue ;
242+ }
243+
227244 $ data = [$ paramName ];
228245 $ phpcsFile ->addWarning ($ error , $ info ['position ' ], $ info ['errorcode ' ], $ data );
229246 }
0 commit comments