Skip to content

Commit 236fffc

Browse files
committed
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 1106d65 commit 236fffc

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
@@ -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()

0 commit comments

Comments
 (0)