Skip to content

Commit 5632363

Browse files
jrfnlDannyvdSluijs
andcommitted
Squiz/ControlSignature: fix grammar for various error messages
Correct pluralization of the word space/spaces depending on the spacing value. Includes adding tests for the `$requiredSpacesBeforeColon` property being set to a > 1 value. Co-authored-by: Danny van der Sluijs <danny.van.der.sluijs@infi.nl>
1 parent d785815 commit 5632363

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

src/Standards/Squiz/Sniffs/ControlStructures/ControlSignatureSniff.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,15 @@ public function process(File $phpcsFile, $stackPtr)
105105
}
106106

107107
if ($found !== $expected) {
108-
$error = 'Expected %s space(s) after %s keyword; %s found';
108+
$pluralizeSpace = 's';
109+
if ($expected === 1) {
110+
$pluralizeSpace = '';
111+
}
112+
113+
$error = 'Expected %s space%s after %s keyword; %s found';
109114
$data = [
110115
$expected,
116+
$pluralizeSpace,
111117
strtoupper($tokens[$stackPtr]['content']),
112118
$found,
113119
];
@@ -120,7 +126,7 @@ public function process(File $phpcsFile, $stackPtr)
120126
$phpcsFile->fixer->replaceToken(($stackPtr + 1), str_repeat(' ', $expected));
121127
}
122128
}
123-
}
129+
}//end if
124130

125131
// Single space after closing parenthesis.
126132
if (isset($tokens[$stackPtr]['parenthesis_closer']) === true
@@ -146,9 +152,15 @@ public function process(File $phpcsFile, $stackPtr)
146152
}
147153

148154
if ($found !== $expected) {
149-
$error = 'Expected %s space(s) after closing parenthesis; found %s';
155+
$pluralizeSpace = 's';
156+
if ($expected === 1) {
157+
$pluralizeSpace = '';
158+
}
159+
160+
$error = 'Expected %s space%s after closing parenthesis; found %s';
150161
$data = [
151162
$expected,
163+
$pluralizeSpace,
152164
$found,
153165
];
154166

src/Standards/Squiz/Tests/ControlStructures/ControlSignatureUnitTest.inc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,17 @@ $r = match ($x) {
305305

306306
$r = match($x){1 => 1};
307307

308+
// @codingStandardsChangeSetting Squiz.ControlStructures.ControlSignature requiredSpacesBeforeColon 2
309+
if ($a == 5):
310+
echo "a equals 5";
311+
echo "...";
312+
elseif ($a == 6) :
313+
echo "a equals 6";
314+
echo "!!!";
315+
else :
316+
echo "a is neither 5 nor 6";
317+
endif;
318+
308319
// Reset property.
309320
// @codingStandardsChangeSetting Squiz.ControlStructures.ControlSignature requiredSpacesBeforeColon 1
310321

src/Standards/Squiz/Tests/ControlStructures/ControlSignatureUnitTest.inc.fixed

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,17 @@ $r = match ($x) {
309309
$r = match ($x) {
310310
1 => 1};
311311

312+
// @codingStandardsChangeSetting Squiz.ControlStructures.ControlSignature requiredSpacesBeforeColon 2
313+
if ($a == 5) :
314+
echo "a equals 5";
315+
echo "...";
316+
elseif ($a == 6) :
317+
echo "a equals 6";
318+
echo "!!!";
319+
else :
320+
echo "a is neither 5 nor 6";
321+
endif;
322+
312323
// Reset property.
313324
// @codingStandardsChangeSetting Squiz.ControlStructures.ControlSignature requiredSpacesBeforeColon 1
314325

src/Standards/Squiz/Tests/ControlStructures/ControlSignatureUnitTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public function getErrorList($testFile='ControlSignatureUnitTest.inc')
7777
$errors[279] = 1;
7878
$errors[283] = 1;
7979
$errors[306] = 3;
80+
$errors[309] = 1;
81+
$errors[315] = 1;
8082
}//end if
8183

8284
return $errors;

0 commit comments

Comments
 (0)