Skip to content

Commit a2c048b

Browse files
authored
Merge pull request #487 from rodrigoprimo/test-coverage-array-indent
Generic/ArrayIndent: improve code coverage and implement a few small improvements to the sniff code
2 parents 05f8b21 + 3a2230c commit a2c048b

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
6262
// Determine how far indented the entire array declaration should be.
6363
$ignore = Tokens::$emptyTokens;
6464
$ignore[] = T_DOUBLE_ARROW;
65-
$ignore[] = T_COMMA;
6665
$prev = $phpcsFile->findPrevious($ignore, ($stackPtr - 1), null, true);
6766
$start = $phpcsFile->findStartOfStatement($prev);
6867
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $start, true);
@@ -152,28 +151,27 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
152151
$error = 'Closing brace of array declaration must be on a new line';
153152
$fix = $phpcsFile->addFixableError($error, $arrayEnd, 'CloseBraceNotNewLine');
154153
if ($fix === true) {
155-
$padding = $phpcsFile->eolChar.str_repeat(' ', $expectedIndent);
154+
$padding = $phpcsFile->eolChar.str_repeat(' ', $startIndent);
156155
$phpcsFile->fixer->addContentBefore($arrayEnd, $padding);
157156
}
158157

159158
return;
160159
}
161160

162161
// The close brace must be indented one stop less.
163-
$expectedIndent -= $this->indent;
164-
$foundIndent = ($tokens[$arrayEnd]['column'] - 1);
165-
if ($foundIndent === $expectedIndent) {
162+
$foundIndent = ($tokens[$arrayEnd]['column'] - 1);
163+
if ($foundIndent === $startIndent) {
166164
return;
167165
}
168166

169167
$pluralizeSpace = 's';
170-
if ($expectedIndent === 1) {
168+
if ($startIndent === 1) {
171169
$pluralizeSpace = '';
172170
}
173171

174172
$error = 'Array close brace not indented correctly; expected %s space%s but found %s';
175173
$data = [
176-
$expectedIndent,
174+
$startIndent,
177175
$pluralizeSpace,
178176
$foundIndent,
179177
];
@@ -182,7 +180,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
182180
return;
183181
}
184182

185-
$padding = str_repeat(' ', $expectedIndent);
183+
$padding = str_repeat(' ', $startIndent);
186184
if ($foundIndent === 0) {
187185
$phpcsFile->fixer->addContentBefore($arrayEnd, $padding);
188186
} else {

src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,6 @@ $var = [
149149
];
150150

151151
// phpcs:set Generic.Arrays.ArrayIndent indent 4
152+
153+
$array = [1,
154+
];

src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc.fixed

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,6 @@ $var = [
150150
];
151151

152152
// phpcs:set Generic.Arrays.ArrayIndent indent 4
153+
154+
$array = [1,
155+
];

0 commit comments

Comments
 (0)