Skip to content

Commit fd7a503

Browse files
jrfnlgsherwood
authored andcommitted
PHP 8.0 | Pear/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 bca9f7c commit fd7a503

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

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

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

572572
if ($inArg === false) {
573573
$argStart = $nextCode;
574-
$argEnd = $phpcsFile->findEndOfStatement($nextCode);
574+
$argEnd = $phpcsFile->findEndOfStatement($nextCode, [T_COLON]);
575575
}
576576
}//end if
577577

@@ -608,7 +608,7 @@ public function processMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $
608608
}//end if
609609

610610
$argStart = $next;
611-
$argEnd = $phpcsFile->findEndOfStatement($next);
611+
$argEnd = $phpcsFile->findEndOfStatement($next, [T_COLON]);
612612
}//end if
613613
}//end for
614614

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,3 +538,26 @@ $val = namespace\functionCall(
538538
$arg,
539539
$arg2
540540
);
541+
542+
// PHP 8.0 named parameters.
543+
array_fill_keys(
544+
keys: range(
545+
1,
546+
12,
547+
),
548+
value: true,
549+
);
550+
551+
array_fill_keys(
552+
keys: range( 1,
553+
12,
554+
), value: true,
555+
);
556+
557+
// phpcs:set PEAR.Functions.FunctionCallSignature allowMultipleArguments false
558+
array_fill_keys(
559+
keys: range( 1,
560+
12,
561+
), value: true,
562+
);
563+
// 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
@@ -553,3 +553,29 @@ $val = namespace\functionCall(
553553
$arg,
554554
$arg2
555555
);
556+
557+
// PHP 8.0 named parameters.
558+
array_fill_keys(
559+
keys: range(
560+
1,
561+
12,
562+
),
563+
value: true,
564+
);
565+
566+
array_fill_keys(
567+
keys: range(
568+
1,
569+
12,
570+
), value: true,
571+
);
572+
573+
// phpcs:set PEAR.Functions.FunctionCallSignature allowMultipleArguments false
574+
array_fill_keys(
575+
keys: range(
576+
1,
577+
12,
578+
),
579+
value: true,
580+
);
581+
// 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
@@ -107,6 +107,11 @@ public function getErrorList()
107107
533 => 2,
108108
534 => 1,
109109
536 => 2,
110+
552 => 1,
111+
553 => 1,
112+
559 => 1,
113+
560 => 1,
114+
561 => 1,
110115
];
111116

112117
}//end getErrorList()

0 commit comments

Comments
 (0)