Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,11 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
if ($tokens[$valuePointer]['code'] === T_CLOSURE
|| $tokens[$valuePointer]['code'] === T_FN
) {
$ignoreTokens += [T_STATIC => T_STATIC];
// Check if the closure is static, if it is, override the value pointer as indices before did not do it correctly.
$staticPointer = $phpcsFile->findPrevious($ignoreTokens, ($valuePointer - 1), ($arrayStart + 1), true);
if ($staticPointer !== false && $tokens[$staticPointer]['code'] === T_STATIC) {
$valuePointer = $staticPointer;
}
}

$previous = $phpcsFile->findPrevious($ignoreTokens, ($valuePointer - 1), ($arrayStart + 1), true);
Expand Down
11 changes: 11 additions & 0 deletions src/Standards/Squiz/Tests/Arrays/ArrayDeclarationUnitTest.3.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

$closure = static function(): \Generator
{
yield 'test case' => [
1, static fn (float $item): float => match ($item) {
2.0 => 3.0,
default => $item
},
];
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$closure = static function(): \Generator
{
yield 'test case' => [
1,
static fn (float $item): float => match ($item) {
2.0 => 3.0,
default => $item
},
];
};
4 changes: 4 additions & 0 deletions src/Standards/Squiz/Tests/Arrays/ArrayDeclarationUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ public function getErrorList($testFile='')
519 => 1,
526 => 1,
];
case 'ArrayDeclarationUnitTest.3.inc':
return [
6 => 1,
];
default:
return [];
}//end switch
Expand Down