Skip to content

Commit

Permalink
PHP 8.0 | Pear/FunctionCallSignature: support named parameters
Browse files Browse the repository at this point in the history
The `File::findEndOfStatement()` method regards a `T_COLON` as the end of a statement, while for function call arguments using named parameters, the colon is part of the parameter name declaration and should be disregarded when determining the end of the statement.

Fixed now.

Includes unit tests.
  • Loading branch information
jrfnl committed Mar 4, 2021
1 parent 1106d65 commit 236fffc
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ public function processMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $

if ($inArg === false) {
$argStart = $nextCode;
$argEnd = $phpcsFile->findEndOfStatement($nextCode);
$argEnd = $phpcsFile->findEndOfStatement($nextCode, [T_COLON]);
}
}//end if

Expand Down Expand Up @@ -618,7 +618,7 @@ public function processMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $
}//end if

$argStart = $next;
$argEnd = $phpcsFile->findEndOfStatement($next);
$argEnd = $phpcsFile->findEndOfStatement($next, [T_COLON]);
}//end if
}//end for

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,3 +525,26 @@ return trim(preg_replace_callback(

$a = ['a' => function ($b) { return $b; }];
$a['a']( 1 );

// PHP 8.0 named parameters.
array_fill_keys(
keys: range(
1,
12,
),
value: true,
);

array_fill_keys(
keys: range( 1,
12,
), value: true,
);

// phpcs:set PEAR.Functions.FunctionCallSignature allowMultipleArguments false
array_fill_keys(
keys: range( 1,
12,
), value: true,
);
// phpcs:set PEAR.Functions.FunctionCallSignature allowMultipleArguments true
Original file line number Diff line number Diff line change
Expand Up @@ -537,3 +537,29 @@ return trim(

$a = ['a' => function ($b) { return $b; }];
$a['a'](1);

// PHP 8.0 named parameters.
array_fill_keys(
keys: range(
1,
12,
),
value: true,
);

array_fill_keys(
keys: range(
1,
12,
), value: true,
);

// phpcs:set PEAR.Functions.FunctionCallSignature allowMultipleArguments false
array_fill_keys(
keys: range(
1,
12,
),
value: true,
);
// phpcs:set PEAR.Functions.FunctionCallSignature allowMultipleArguments true
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ public function getErrorList($testFile='FunctionCallSignatureUnitTest.inc')
523 => 1,
524 => 3,
527 => 2,
539 => 1,
540 => 1,
546 => 1,
547 => 1,
548 => 1,
];

}//end getErrorList()
Expand Down

0 comments on commit 236fffc

Please sign in to comment.