diff --git a/src/Standards/Generic/Sniffs/Arrays/ArrayIndentSniff.php b/src/Standards/Generic/Sniffs/Arrays/ArrayIndentSniff.php index 87da8f3cf9..b6e3d37d70 100644 --- a/src/Standards/Generic/Sniffs/Arrays/ArrayIndentSniff.php +++ b/src/Standards/Generic/Sniffs/Arrays/ArrayIndentSniff.php @@ -62,7 +62,6 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array // Determine how far indented the entire array declaration should be. $ignore = Tokens::$emptyTokens; $ignore[] = T_DOUBLE_ARROW; - $ignore[] = T_COMMA; $prev = $phpcsFile->findPrevious($ignore, ($stackPtr - 1), null, true); $start = $phpcsFile->findStartOfStatement($prev); $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $start, true); @@ -152,7 +151,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array $error = 'Closing brace of array declaration must be on a new line'; $fix = $phpcsFile->addFixableError($error, $arrayEnd, 'CloseBraceNotNewLine'); if ($fix === true) { - $padding = $phpcsFile->eolChar.str_repeat(' ', $expectedIndent); + $padding = $phpcsFile->eolChar.str_repeat(' ', $startIndent); $phpcsFile->fixer->addContentBefore($arrayEnd, $padding); } @@ -160,20 +159,19 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array } // The close brace must be indented one stop less. - $expectedIndent -= $this->indent; - $foundIndent = ($tokens[$arrayEnd]['column'] - 1); - if ($foundIndent === $expectedIndent) { + $foundIndent = ($tokens[$arrayEnd]['column'] - 1); + if ($foundIndent === $startIndent) { return; } $pluralizeSpace = 's'; - if ($expectedIndent === 1) { + if ($startIndent === 1) { $pluralizeSpace = ''; } $error = 'Array close brace not indented correctly; expected %s space%s but found %s'; $data = [ - $expectedIndent, + $startIndent, $pluralizeSpace, $foundIndent, ]; @@ -182,7 +180,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array return; } - $padding = str_repeat(' ', $expectedIndent); + $padding = str_repeat(' ', $startIndent); if ($foundIndent === 0) { $phpcsFile->fixer->addContentBefore($arrayEnd, $padding); } else { diff --git a/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc b/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc index 6f418ca1f3..06ebca78f8 100644 --- a/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc +++ b/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc @@ -149,3 +149,6 @@ $var = [ ]; // phpcs:set Generic.Arrays.ArrayIndent indent 4 + +$array = [1, +]; diff --git a/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc.fixed b/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc.fixed index 1ea8dd1e6f..03f508dbe5 100644 --- a/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc.fixed +++ b/src/Standards/Generic/Tests/Arrays/ArrayIndentUnitTest.inc.fixed @@ -150,3 +150,6 @@ $var = [ ]; // phpcs:set Generic.Arrays.ArrayIndent indent 4 + +$array = [1, +];