Skip to content

Commit 12645d7

Browse files
committed
Generic/ArrayIndent: avoid extra calls to ArrayIndent::processMultiLineArray()
This commit fixes a small inefficiency when fixing the `CloseBraceNotNewLine` error. Previously, the sniff would add the new line and the number of spaces used for an array element (which is more tha what should be used for the array closing brace). Then on a subsequent call to processMultiLineArray(), it would detect the wrong number of spaces for the closing brace and it would fix it. Now, the sniff will use the correct number of spaces when adding the newline.
1 parent 16e9b04 commit 12645d7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Standards/Generic/Sniffs/Arrays/ArrayIndentSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,20 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
146146
}
147147
}//end foreach
148148

149+
$expectedCloseBraceIndent = ($expectedElementIndent - $this->indent);
149150
$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($arrayEnd - 1), null, true);
150151
if ($tokens[$prev]['line'] === $tokens[$arrayEnd]['line']) {
151152
$error = 'Closing brace of array declaration must be on a new line';
152153
$fix = $phpcsFile->addFixableError($error, $arrayEnd, 'CloseBraceNotNewLine');
153154
if ($fix === true) {
154-
$padding = $phpcsFile->eolChar.str_repeat(' ', $expectedElementIndent);
155+
$padding = $phpcsFile->eolChar.str_repeat(' ', $expectedCloseBraceIndent);
155156
$phpcsFile->fixer->addContentBefore($arrayEnd, $padding);
156157
}
157158

158159
return;
159160
}
160161

161162
// The close brace must be indented one stop less.
162-
$expectedCloseBraceIndent = ($expectedElementIndent - $this->indent);
163163
$foundIndent = ($tokens[$arrayEnd]['column'] - 1);
164164
if ($foundIndent === $expectedCloseBraceIndent) {
165165
return;

0 commit comments

Comments
 (0)