Skip to content

Commit

Permalink
Fix ForbiddenFunctionsSniff not counting arguments correctly
Browse files Browse the repository at this point in the history
Array arguments use T_OPEN_SHORT_ARRAY, not T_OPEN_SQUARE_BRACKET.

Bug: T341750
Change-Id: Ib844f3532ff70e010d1a065ebebbd2355f96d4be
  • Loading branch information
Daimona committed Jul 12, 2023
1 parent 482d9e5 commit 59f6a9b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions MediaWiki/Sniffs/Usage/ForbiddenFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ private function argCount( File $phpcsFile, int $parenthesis ): int {
$searchTokens = [
T_OPEN_CURLY_BRACKET,
T_OPEN_SQUARE_BRACKET,
T_OPEN_SHORT_ARRAY,
T_OPEN_PARENTHESIS,
T_COMMA
];
Expand All @@ -219,6 +220,12 @@ private function argCount( File $phpcsFile, int $parenthesis ): int {
$next = $tokens[$next]['parenthesis_closer'];
}
break;
case T_OPEN_SHORT_ARRAY:
if ( isset( $tokens[$next]['bracket_closer'] ) ) {
// jump to closing bracket to ignore commas between opener and closer
$next = $tokens[$next]['bracket_closer'];
}
break;
case T_COMMA:
$argCount++;
break;
Expand Down
1 change: 1 addition & 0 deletions MediaWiki/Tests/files/Usage/forbidden_functions_usage.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
define( 'ALLOWED', 42 );
define( 'FORBIDDEN_CASE_SENSITIVE', 42, true );
eval( '' );
define( 'ARRAY_AS_SECOND_ARGUMENT_ALLOWED', [ 1, 2 ] );
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ $a = FooBar::sizeof['b'];
define( 'ALLOWED', 42 );
define( 'FORBIDDEN_CASE_SENSITIVE', 42, true );
eval( '' );
define( 'ARRAY_AS_SECOND_ARGUMENT_ALLOWED', [ 1, 2 ] );

0 comments on commit 59f6a9b

Please sign in to comment.