Skip to content

Commit 16e9b04

Browse files
committed
Generic/ArrayIndent: don't use the same variable for different things
The variable `$expectedIndent` was being used for two different things: the expected indentation value for the array elements and for the array closing brace. This changes the code to use two different variables, one for each expected indentation.
1 parent 94cd19a commit 16e9b04

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
9999
return;
100100
}//end if
101101

102-
$expectedIndent = ($startIndent + $this->indent);
102+
$expectedElementIndent = ($startIndent + $this->indent);
103103

104104
foreach ($indices as $index) {
105105
if (isset($index['index_start']) === true) {
@@ -118,18 +118,18 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
118118
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $start, true);
119119

120120
$foundIndent = ($tokens[$first]['column'] - 1);
121-
if ($foundIndent === $expectedIndent) {
121+
if ($foundIndent === $expectedElementIndent) {
122122
continue;
123123
}
124124

125125
$pluralizeSpace = 's';
126-
if ($expectedIndent === 1) {
126+
if ($expectedElementIndent === 1) {
127127
$pluralizeSpace = '';
128128
}
129129

130130
$error = 'Array key not indented correctly; expected %s space%s but found %s';
131131
$data = [
132-
$expectedIndent,
132+
$expectedElementIndent,
133133
$pluralizeSpace,
134134
$foundIndent,
135135
];
@@ -138,7 +138,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
138138
continue;
139139
}
140140

141-
$padding = str_repeat(' ', $expectedIndent);
141+
$padding = str_repeat(' ', $expectedElementIndent);
142142
if ($foundIndent === 0) {
143143
$phpcsFile->fixer->addContentBefore($first, $padding);
144144
} else {
@@ -151,28 +151,28 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
151151
$error = 'Closing brace of array declaration must be on a new line';
152152
$fix = $phpcsFile->addFixableError($error, $arrayEnd, 'CloseBraceNotNewLine');
153153
if ($fix === true) {
154-
$padding = $phpcsFile->eolChar.str_repeat(' ', $expectedIndent);
154+
$padding = $phpcsFile->eolChar.str_repeat(' ', $expectedElementIndent);
155155
$phpcsFile->fixer->addContentBefore($arrayEnd, $padding);
156156
}
157157

158158
return;
159159
}
160160

161161
// The close brace must be indented one stop less.
162-
$expectedIndent -= $this->indent;
163-
$foundIndent = ($tokens[$arrayEnd]['column'] - 1);
164-
if ($foundIndent === $expectedIndent) {
162+
$expectedCloseBraceIndent = ($expectedElementIndent - $this->indent);
163+
$foundIndent = ($tokens[$arrayEnd]['column'] - 1);
164+
if ($foundIndent === $expectedCloseBraceIndent) {
165165
return;
166166
}
167167

168168
$pluralizeSpace = 's';
169-
if ($expectedIndent === 1) {
169+
if ($expectedCloseBraceIndent === 1) {
170170
$pluralizeSpace = '';
171171
}
172172

173173
$error = 'Array close brace not indented correctly; expected %s space%s but found %s';
174174
$data = [
175-
$expectedIndent,
175+
$expectedCloseBraceIndent,
176176
$pluralizeSpace,
177177
$foundIndent,
178178
];
@@ -181,7 +181,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
181181
return;
182182
}
183183

184-
$padding = str_repeat(' ', $expectedIndent);
184+
$padding = str_repeat(' ', $expectedCloseBraceIndent);
185185
if ($foundIndent === 0) {
186186
$phpcsFile->fixer->addContentBefore($arrayEnd, $padding);
187187
} else {

0 commit comments

Comments
 (0)