Skip to content

Commit 8298b64

Browse files
🐛 Fix arrow alignement for multi lines indexes
1 parent fbda174 commit 8298b64

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

SymfonyCustom/Sniffs/Arrays/ArrayDeclarationSniff.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,16 @@ public function processMultiLineArray(File $phpcsFile, int $stackPtr, int $start
391391
$indexEnd = $phpcsFile->findPrevious(T_WHITESPACE, $nextToken - 1, $start, true);
392392
$indexStart = $phpcsFile->findStartOfStatement($indexEnd);
393393

394+
// Handle multi-lines index.
395+
while ($tokens[$indexStart]['line'] !== $tokens[$indexEnd]['line']) {
396+
$indexStart = $phpcsFile->findNext(
397+
Tokens::$emptyTokens,
398+
$indexStart + 1,
399+
$indexEnd + 1,
400+
true
401+
);
402+
}
403+
394404
if ($indexStart === $indexEnd) {
395405
$currentEntry['index'] = $indexEnd;
396406
$currentEntry['index_content'] = $tokens[$indexEnd]['content'];

SymfonyCustom/Tests/Arrays/ArrayDeclarationUnitTest.inc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,15 @@ return [
149149
];
150150

151151
[1 => 2 , 2=>3,4 => 5];
152+
153+
$array = [
154+
'lonnnnnnggggg' => 'good',
155+
'short'
156+
=> 'bad',
157+
];
158+
159+
$array = [
160+
'lonnnnnngggggg' => 'good',
161+
$ab .
162+
'second' => 'bad',
163+
];

SymfonyCustom/Tests/Arrays/ArrayDeclarationUnitTest.inc.fixed

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,14 @@ return [
147147
];
148148

149149
[1 => 2, 2 => 3, 4 => 5];
150+
151+
$array = [
152+
'lonnnnnnggggg' => 'good',
153+
'short' => 'bad',
154+
];
155+
156+
$array = [
157+
'lonnnnnngggggg' => 'good',
158+
$ab .
159+
'second' => 'bad',
160+
];

SymfonyCustom/Tests/Arrays/ArrayDeclarationUnitTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ protected function getErrorList(): array
4747
142 => 1,
4848
148 => 1,
4949
151 => 7,
50+
156 => 1,
51+
162 => 1,
5052
];
5153
}
5254

0 commit comments

Comments
 (0)