Skip to content

Commit a32f46c

Browse files
committed
SlevomatCodingStandard.Arrays.DisallowPartiallyKeyed: Fixed false positive
1 parent 0411d16 commit a32f46c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

SlevomatCodingStandard/Helpers/ArrayKeyValue.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace SlevomatCodingStandard\Helpers;
44

55
use PHP_CodeSniffer\Files\File;
6+
use function array_key_exists;
67
use function in_array;
78
use function ltrim;
89
use function rtrim;
@@ -132,6 +133,18 @@ private function addValues(File $phpcsFile): void
132133
} elseif ($token['code'] === T_ELLIPSIS) {
133134
$this->unpacking = true;
134135
} elseif ($this->pointerArrow === null) {
136+
if (array_key_exists('scope_closer', $token) && $token['scope_closer'] > $i) {
137+
$key .= TokenHelper::getContent($phpcsFile, $i, $token['scope_closer']);
138+
$i = $token['scope_closer'];
139+
continue;
140+
}
141+
142+
if (array_key_exists('parenthesis_closer', $token)) {
143+
$key .= TokenHelper::getContent($phpcsFile, $i, $token['parenthesis_closer']);
144+
$i = $token['parenthesis_closer'];
145+
continue;
146+
}
147+
135148
if ($firstNonWhitespace === null && $token['code'] !== T_WHITESPACE) {
136149
$firstNonWhitespace = $i;
137150
}

tests/Sniffs/Arrays/data/disallowPartiallyKeyedNoErrors.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,14 @@
2323
'baz' => 'baz',
2424
...$a
2525
);
26+
27+
[
28+
'bail',
29+
'array',
30+
'required',
31+
static function (array $value): array {
32+
foreach ($value as $x => $z) {
33+
$x + $z;
34+
}
35+
},
36+
];

0 commit comments

Comments
 (0)