Skip to content

Commit 1139e61

Browse files
committed
fix #2 closing array bracket must be on own line
1 parent e14c94e commit 1139e61

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

Sniffs/Formatting/ArrayAlignmentSniff.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
6767

6868
if ($tokens[$start]['line'] === $tokens[$end]['line']) {
6969
return;
70+
} if ($tokens[$end - 2]['line'] === $tokens[$end]['line']) {
71+
$phpcsFile->addError(
72+
sprintf(
73+
'closing %s of array must in own line',
74+
($current['code'] === T_ARRAY) ? 'parenthesis' : 'bracket'
75+
),
76+
$end
77+
);
7078
}
7179

7280
$assignments = array();

Tests/Formatting/ArrayAlignmentUnitTest.fail.inc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,18 @@ $a = [
135135
98765432
136136
=> 'fail',
137137
];
138+
139+
$values = [
140+
'Test:1' => [
141+
'object_id' => 1,
142+
'object_class' => 'Test',
143+
'object_class_name' => 'TestClass',
144+
'object_name' => 'TestObject',
145+
'id' => 'Test:1', ],
146+
'Test:2' => [
147+
'object_id' => 2,
148+
'object_class' => 'Test',
149+
'object_class_name' => 'TestClass',
150+
'object_name' => 'TestObject',
151+
'id' => 'Test:2', ], ];
152+

Tests/Formatting/ArrayAlignmentUnitTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ protected function getErrorList($testFile = '')
7575
132 => 1,
7676
134 => 1,
7777
136 => 2,
78+
145 => 1,
79+
151 => 2,
7880
);
7981
}
8082

0 commit comments

Comments
 (0)