Skip to content

Commit 02c1c56

Browse files
committed
Add none option or array declaration.
1 parent bfa3560 commit 02c1c56

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

PhpCollective/Sniffs/Formatting/ArrayDeclarationSniff.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,10 +657,8 @@ protected function processMultiLineIndentation(File $phpcsFile, int $arrayStart,
657657
continue;
658658
}
659659

660-
// In 'assoc' mode, only fix associative items
661-
if ($this->multiLineIndentationMode === 'assoc' && !$p['is_associative']) {
662-
continue;
663-
}
660+
// In 'assoc' mode, when we have mixed items on a line, we need to fix all of them
661+
// Don't skip non-associative items when they're on the same line as associative ones
664662

665663
$targetPtr = $p['key'] ?? $p['value'];
666664

tests/PhpCollective/Sniffs/Formatting/ArrayDeclarationSniffTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ArrayDeclarationSniffTest extends TestCase
1717
*/
1818
public function testDocBlockConstSniffer(): void
1919
{
20-
$this->assertSnifferFindsErrors(new ArrayDeclarationSniff(), 3);
20+
$this->assertSnifferFindsErrors(new ArrayDeclarationSniff(), 4);
2121
}
2222

2323
/**

tests/_data/ArrayDeclaration/after.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,13 @@ public function test(): void
2828
'first' => ['a', 'b'],
2929
'second' => ['c', 'd'],
3030
];
31+
32+
// Mixed associative and non-associative items - SHOULD be flagged
33+
$url = [
34+
'controller' => 'ControllerName',
35+
'action' => 'view',
36+
$uuid,
37+
'?' => ['pdf' => 1],
38+
];
3139
}
3240
}

tests/_data/ArrayDeclaration/before.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,12 @@ public function test(): void
2424
$multi = [
2525
'first' => ['a', 'b'], 'second' => ['c', 'd'],
2626
];
27+
28+
// Mixed associative and non-associative items - SHOULD be flagged
29+
$url = [
30+
'controller' => 'ControllerName',
31+
'action' => 'view', $uuid,
32+
'?' => ['pdf' => 1],
33+
];
2734
}
2835
}

0 commit comments

Comments
 (0)