Skip to content

Commit a4272b6

Browse files
committed
Merge branch 'php-8.0/3253-psr2-functioncallsignature-support-named-params' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents f6f44e1 + e890cc3 commit a4272b6

8 files changed

+112
-4
lines changed

src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ public function processMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $
581581

582582
if ($inArg === false) {
583583
$argStart = $nextCode;
584-
$argEnd = $phpcsFile->findEndOfStatement($nextCode);
584+
$argEnd = $phpcsFile->findEndOfStatement($nextCode, [T_COLON]);
585585
}
586586
}//end if
587587

@@ -618,7 +618,7 @@ public function processMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $
618618
}//end if
619619

620620
$argStart = $next;
621-
$argEnd = $phpcsFile->findEndOfStatement($next);
621+
$argEnd = $phpcsFile->findEndOfStatement($next, [T_COLON]);
622622
}//end if
623623
}//end for
624624

src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,3 +525,26 @@ return trim(preg_replace_callback(
525525

526526
$a = ['a' => function ($b) { return $b; }];
527527
$a['a']( 1 );
528+
529+
// PHP 8.0 named parameters.
530+
array_fill_keys(
531+
keys: range(
532+
1,
533+
12,
534+
),
535+
value: true,
536+
);
537+
538+
array_fill_keys(
539+
keys: range( 1,
540+
12,
541+
), value: true,
542+
);
543+
544+
// phpcs:set PEAR.Functions.FunctionCallSignature allowMultipleArguments false
545+
array_fill_keys(
546+
keys: range( 1,
547+
12,
548+
), value: true,
549+
);
550+
// phpcs:set PEAR.Functions.FunctionCallSignature allowMultipleArguments true

src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc.fixed

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,3 +537,29 @@ return trim(
537537

538538
$a = ['a' => function ($b) { return $b; }];
539539
$a['a'](1);
540+
541+
// PHP 8.0 named parameters.
542+
array_fill_keys(
543+
keys: range(
544+
1,
545+
12,
546+
),
547+
value: true,
548+
);
549+
550+
array_fill_keys(
551+
keys: range(
552+
1,
553+
12,
554+
), value: true,
555+
);
556+
557+
// phpcs:set PEAR.Functions.FunctionCallSignature allowMultipleArguments false
558+
array_fill_keys(
559+
keys: range(
560+
1,
561+
12,
562+
),
563+
value: true,
564+
);
565+
// phpcs:set PEAR.Functions.FunctionCallSignature allowMultipleArguments true

src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ public function getErrorList($testFile='FunctionCallSignatureUnitTest.inc')
126126
523 => 1,
127127
524 => 3,
128128
527 => 2,
129+
539 => 1,
130+
540 => 1,
131+
546 => 1,
132+
547 => 1,
133+
548 => 1,
129134
];
130135

131136
}//end getErrorList()

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)