Skip to content

Commit

Permalink
PHP 8.0 | PSR2/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 236fffc commit e890cc3
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 @@ -48,7 +48,7 @@ public function isMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $token

$closeBracket = $tokens[$openBracket]['parenthesis_closer'];

$end = $phpcsFile->findEndOfStatement($openBracket + 1);
$end = $phpcsFile->findEndOfStatement(($openBracket + 1), [T_COLON]);
while ($tokens[$end]['code'] === T_COMMA) {
// If the next bit of code is not on the same line, this is a
// multi-line function call.
Expand All @@ -61,7 +61,7 @@ public function isMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $token
return true;
}

$end = $phpcsFile->findEndOfStatement($next);
$end = $phpcsFile->findEndOfStatement($next, [T_COLON]);
}

// We've reached the last argument, so see if the next content
Expand Down
23 changes: 23 additions & 0 deletions src/Standards/PSR2/Tests/Methods/FunctionCallSignatureUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,26 @@ function (array $term) use ($mode): string {
},
$search
));

// 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 PSR2.Methods.FunctionCallSignature allowMultipleArguments true
array_fill_keys(
keys: range( 1,
12,
), value: true,
);
// phpcs:set PSR2.Methods.FunctionCallSignature allowMultipleArguments false
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,29 @@ return trim(preg_replace_callback(
},
$search
));

// 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 PSR2.Methods.FunctionCallSignature allowMultipleArguments true
array_fill_keys(
keys: range(
1,
12,
), value: true,
);
// phpcs:set PSR2.Methods.FunctionCallSignature allowMultipleArguments false
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public function getErrorList()
234 => 1,
242 => 1,
243 => 1,
256 => 1,
257 => 1,
258 => 1,
263 => 1,
264 => 1,
];

}//end getErrorList()
Expand Down

0 comments on commit e890cc3

Please sign in to comment.