Skip to content

Commit 67c82d9

Browse files
committed
Fixed bug #3502 : A match statement within an array produces Squiz.Arrays.ArrayDeclaration.NoKeySpecified
1 parent f653fd2 commit 67c82d9

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
3939
-- Squiz.Commenting.DocCommentAlignment
4040
-- Squiz.Commenting.VariableComment
4141
-- Thanks to Juliette Reinders Folmer for the patches
42+
- Fixed bug #3502 : A match statement within an array produces Squiz.Arrays.ArrayDeclaration.NoKeySpecified
4243
- Fixed bug #3503 : Squiz.Commenting.FunctionComment.ThrowsNoFullStop false positive when one line @throw
4344
</notes>
4445
<contents>

src/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
374374
|| $tokens[$nextToken]['code'] === T_OPEN_SHORT_ARRAY
375375
|| $tokens[$nextToken]['code'] === T_CLOSURE
376376
|| $tokens[$nextToken]['code'] === T_FN
377+
|| $tokens[$nextToken]['code'] === T_MATCH
377378
) {
378379
// Let subsequent calls of this test handle nested arrays.
379380
if ($tokens[$lastToken]['code'] !== T_DOUBLE_ARROW) {

src/Standards/Squiz/Tests/Arrays/ArrayDeclarationUnitTest.1.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,13 @@ yield array(
475475
static fn () : string => '',
476476
);
477477

478+
$foo = [
479+
'foo' => match ($anything) {
480+
'foo' => 'bar',
481+
default => null,
482+
},
483+
];
484+
478485
// Intentional syntax error.
479486
$a = array(
480487
'a' =>

src/Standards/Squiz/Tests/Arrays/ArrayDeclarationUnitTest.1.inc.fixed

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,13 @@ yield array(
511511
static fn () : string => '',
512512
);
513513

514+
$foo = [
515+
'foo' => match ($anything) {
516+
'foo' => 'bar',
517+
default => null,
518+
},
519+
];
520+
514521
// Intentional syntax error.
515522
$a = array(
516523
'a' =>

0 commit comments

Comments
 (0)