Skip to content

Commit 4cf6bad

Browse files
jrfnlDannyvdSluijs
andcommitted
Generic/ArrayIndent: fix grammar for various error messages
Correct pluralization of the word space/spaces depending on the spacing value. Includes adding tests for the `$indent` property being set to a 1 (open brace) and 0 (item indent, close brace). Co-authored-by: Danny van der Sluijs <danny.van.der.sluijs@infi.nl>
1 parent d46210e commit 4cf6bad

File tree

4 files changed

+105
-3
lines changed

4 files changed

+105
-3
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,15 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
7676
// check indent levels because it's not valid. But we don't enforce exactly
7777
// how far indented it should be.
7878
if ($startIndent < $baseIndent) {
79-
$error = 'Array open brace not indented correctly; expected at least %s spaces but found %s';
79+
$pluralizeSpace = 's';
80+
if ($baseIndent === 1) {
81+
$pluralizeSpace = '';
82+
}
83+
84+
$error = 'Array open brace not indented correctly; expected at least %s space%s but found %s';
8085
$data = [
8186
$baseIndent,
87+
$pluralizeSpace,
8288
$startIndent,
8389
];
8490
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'OpenBraceIncorrect', $data);
@@ -117,9 +123,15 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
117123
continue;
118124
}
119125

120-
$error = 'Array key not indented correctly; expected %s spaces but found %s';
126+
$pluralizeSpace = 's';
127+
if ($expectedIndent === 1) {
128+
$pluralizeSpace = '';
129+
}
130+
131+
$error = 'Array key not indented correctly; expected %s space%s but found %s';
121132
$data = [
122133
$expectedIndent,
134+
$pluralizeSpace,
123135
$foundIndent,
124136
];
125137
$fix = $phpcsFile->addFixableError($error, $first, 'KeyIncorrect', $data);
@@ -154,9 +166,15 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
154166
return;
155167
}
156168

157-
$error = 'Array close brace not indented correctly; expected %s spaces but found %s';
169+
$pluralizeSpace = 's';
170+
if ($expectedIndent === 1) {
171+
$pluralizeSpace = '';
172+
}
173+
174+
$error = 'Array close brace not indented correctly; expected %s space%s but found %s';
158175
$data = [
159176
$expectedIndent,
177+
$pluralizeSpace,
160178
$foundIndent,
161179
];
162180
$fix = $phpcsFile->addFixableError($error, $arrayEnd, 'CloseBraceIncorrect', $data);

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,41 @@ $array = [
111111
name: $value
112112
),
113113
];
114+
115+
// phpcs:set Generic.Arrays.ArrayIndent indent 1
116+
117+
// Testing pluralization of indent text - open brace indent.
118+
$var =
119+
[
120+
1 => 'one',
121+
];
122+
123+
// Testing pluralization of indent text - array item indent.
124+
$var = [
125+
1 => 'one',
126+
2 => 'two',
127+
/* three */ 3 => 'three',
128+
];
129+
130+
// Testing pluralization of indent text - close brace indent.
131+
$var = [
132+
1 => 'one',
133+
];
134+
135+
// phpcs:set Generic.Arrays.ArrayIndent indent 0
136+
137+
// No test for open brace indent as that is _minimum_ and any actual value will be 0 or more, so with indent 0, this will never yield an error.
138+
139+
// Testing pluralization of indent text - array item indent.
140+
$var = [
141+
1 => 'one',
142+
2 => 'two',
143+
/* three */ 3 => 'three',
144+
];
145+
146+
// Testing pluralization of indent text - close brace indent.
147+
$var = [
148+
1 => 'one',
149+
];
150+
151+
// phpcs:set Generic.Arrays.ArrayIndent indent 4

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,41 @@ $array = [
112112
name: $value
113113
),
114114
];
115+
116+
// phpcs:set Generic.Arrays.ArrayIndent indent 1
117+
118+
// Testing pluralization of indent text - open brace indent.
119+
$var =
120+
[
121+
1 => 'one',
122+
];
123+
124+
// Testing pluralization of indent text - array item indent.
125+
$var = [
126+
1 => 'one',
127+
2 => 'two',
128+
/* three */ 3 => 'three',
129+
];
130+
131+
// Testing pluralization of indent text - close brace indent.
132+
$var = [
133+
1 => 'one',
134+
];
135+
136+
// phpcs:set Generic.Arrays.ArrayIndent indent 0
137+
138+
// No test for open brace indent as that is _minimum_ and any actual value will be 0 or more, so with indent 0, this will never yield an error.
139+
140+
// Testing pluralization of indent text - array item indent.
141+
$var = [
142+
1 => 'one',
143+
2 => 'two',
144+
/* three */ 3 => 'three',
145+
];
146+
147+
// Testing pluralization of indent text - close brace indent.
148+
$var = [
149+
1 => 'one',
150+
];
151+
152+
// phpcs:set Generic.Arrays.ArrayIndent indent 4

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ public function getErrorList()
4545
88 => 1,
4646
98 => 1,
4747
110 => 1,
48+
119 => 1,
49+
126 => 1,
50+
127 => 1,
51+
133 => 1,
52+
141 => 1,
53+
142 => 1,
54+
143 => 1,
55+
149 => 1,
4856
];
4957

5058
}//end getErrorList()

0 commit comments

Comments
 (0)