Skip to content

Commit e890cc3

Browse files
committed
PHP 8.0 | PSR2/FunctionCallSignature: support named parameters
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.
1 parent 236fffc commit e890cc3

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

src/Standards/PSR2/Sniffs/Methods/FunctionCallSignatureSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function isMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $token
4848

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

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

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

6767
// We've reached the last argument, so see if the next content

src/Standards/PSR2/Tests/Methods/FunctionCallSignatureUnitTest.inc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,26 @@ function (array $term) use ($mode): string {
242242
},
243243
$search
244244
));
245+
246+
// PHP 8.0 named parameters.
247+
array_fill_keys(
248+
keys: range(
249+
1,
250+
12,
251+
),
252+
value: true,
253+
);
254+
255+
array_fill_keys(
256+
keys: range( 1,
257+
12,
258+
), value: true,
259+
);
260+
261+
// phpcs:set PSR2.Methods.FunctionCallSignature allowMultipleArguments true
262+
array_fill_keys(
263+
keys: range( 1,
264+
12,
265+
), value: true,
266+
);
267+
// phpcs:set PSR2.Methods.FunctionCallSignature allowMultipleArguments false

src/Standards/PSR2/Tests/Methods/FunctionCallSignatureUnitTest.inc.fixed

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,29 @@ return trim(preg_replace_callback(
255255
},
256256
$search
257257
));
258+
259+
// PHP 8.0 named parameters.
260+
array_fill_keys(
261+
keys: range(
262+
1,
263+
12,
264+
),
265+
value: true,
266+
);
267+
268+
array_fill_keys(
269+
keys: range(
270+
1,
271+
12,
272+
),
273+
value: true,
274+
);
275+
276+
// phpcs:set PSR2.Methods.FunctionCallSignature allowMultipleArguments true
277+
array_fill_keys(
278+
keys: range(
279+
1,
280+
12,
281+
), value: true,
282+
);
283+
// phpcs:set PSR2.Methods.FunctionCallSignature allowMultipleArguments false

src/Standards/PSR2/Tests/Methods/FunctionCallSignatureUnitTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ public function getErrorList()
6666
234 => 1,
6767
242 => 1,
6868
243 => 1,
69+
256 => 1,
70+
257 => 1,
71+
258 => 1,
72+
263 => 1,
73+
264 => 1,
6974
];
7075

7176
}//end getErrorList()

0 commit comments

Comments
 (0)