Skip to content

Commit 282306f

Browse files
committed
Fixed alignment false positive when using arrow function as a array value (ref #2703, #2523)
1 parent 15acf50 commit 282306f

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
367367
if ($tokens[$nextToken]['code'] === T_ARRAY
368368
|| $tokens[$nextToken]['code'] === T_OPEN_SHORT_ARRAY
369369
|| $tokens[$nextToken]['code'] === T_CLOSURE
370+
|| $tokens[$nextToken]['code'] === T_FN
370371
) {
371372
// Let subsequent calls of this test handle nested arrays.
372373
if ($tokens[$lastToken]['code'] !== T_DOUBLE_ARROW) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,12 @@ $array = array(
418418
fn() => return 2,
419419
);
420420

421+
$array = array(
422+
1 => '1',
423+
2 => fn ($x) => yield 'a' => $x,
424+
3 => '3',
425+
);
426+
421427
// Intentional syntax error.
422428
$a = array(
423429
'a' =>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,12 @@ $array = array(
446446
fn() => return 2,
447447
);
448448

449+
$array = array(
450+
1 => '1',
451+
2 => fn ($x) => yield 'a' => $x,
452+
3 => '3',
453+
);
454+
449455
// Intentional syntax error.
450456
$a = array(
451457
'a' =>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,12 @@ $array = [
407407
fn() => return 2,
408408
];
409409

410+
$array = [
411+
1 => '1',
412+
2 => fn ($x) => yield 'a' => $x,
413+
3 => '3',
414+
];
415+
410416
// Intentional syntax error.
411417
$a = [
412418
'a' =>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,12 @@ $array = [
433433
fn() => return 2,
434434
];
435435

436+
$array = [
437+
1 => '1',
438+
2 => fn ($x) => yield 'a' => $x,
439+
3 => '3',
440+
];
441+
436442
// Intentional syntax error.
437443
$a = [
438444
'a' =>

0 commit comments

Comments
 (0)