Skip to content

Commit 136ba51

Browse files
committed
Further fix for #3060 (ref #3061, #3112)
Sniff wasn't ignore static arrow functions, or fixing the indent correctly when it actually was incorrect
1 parent 9a9676f commit 136ba51

File tree

6 files changed

+42
-4
lines changed

6 files changed

+42
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,9 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
631631
];
632632
$ignoreTokens += Tokens::$castTokens;
633633

634-
if ($tokens[$valuePointer]['code'] === T_CLOSURE) {
634+
if ($tokens[$valuePointer]['code'] === T_CLOSURE
635+
|| $tokens[$valuePointer]['code'] === T_FN
636+
) {
635637
$ignoreTokens += [T_STATIC => T_STATIC];
636638
}
637639

@@ -667,12 +669,12 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
667669
$found,
668670
];
669671

670-
$fix = $phpcsFile->addFixableError($error, $valuePointer, 'ValueNotAligned', $data);
672+
$fix = $phpcsFile->addFixableError($error, $first, 'ValueNotAligned', $data);
671673
if ($fix === true) {
672674
if ($found === 0) {
673-
$phpcsFile->fixer->addContent(($valuePointer - 1), str_repeat(' ', $expected));
675+
$phpcsFile->fixer->addContent(($first - 1), str_repeat(' ', $expected));
674676
} else {
675-
$phpcsFile->fixer->replaceToken(($valuePointer - 1), str_repeat(' ', $expected));
677+
$phpcsFile->fixer->replaceToken(($first - 1), str_repeat(' ', $expected));
676678
}
677679
}
678680
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ array(
467467
,
468468
);
469469

470+
yield array(
471+
static fn () : string => '',
472+
);
473+
474+
yield array(
475+
static fn () : string => '',
476+
);
477+
470478
// Intentional syntax error.
471479
$a = array(
472480
'a' =>

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,14 @@ array(
503503
,
504504
);
505505

506+
yield array(
507+
static fn () : string => '',
508+
);
509+
510+
yield array(
511+
static fn () : string => '',
512+
);
513+
506514
// Intentional syntax error.
507515
$a = array(
508516
'a' =>

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,14 @@ $c];
456456
,
457457
];
458458

459+
yield [
460+
static fn () : string => '',
461+
];
462+
463+
yield [
464+
static fn () : string => '',
465+
];
466+
459467
// Intentional syntax error.
460468
$a = [
461469
'a' =>

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,14 @@ $foo = [
490490
,
491491
];
492492

493+
yield [
494+
static fn () : string => '',
495+
];
496+
497+
yield [
498+
static fn () : string => '',
499+
];
500+
493501
// Intentional syntax error.
494502
$a = [
495503
'a' =>

src/Standards/Squiz/Tests/Arrays/ArrayDeclarationUnitTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ public function getErrorList($testFile='')
122122
447 => 2,
123123
448 => 3,
124124
467 => 1,
125+
471 => 1,
126+
472 => 1,
125127
];
126128
case 'ArrayDeclarationUnitTest.2.inc':
127129
return [
@@ -206,6 +208,8 @@ public function getErrorList($testFile='')
206208
436 => 2,
207209
437 => 3,
208210
456 => 1,
211+
460 => 1,
212+
461 => 1,
209213
];
210214
default:
211215
return [];

0 commit comments

Comments
 (0)