Skip to content

Commit

Permalink
Squiz/ControlSignature: fix grammar for various error messages
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jrfnl and DannyvdSluijs committed Dec 8, 2023
1 parent d785815 commit 5632363
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
Expand Up @@ -105,9 +105,15 @@ public function process(File $phpcsFile, $stackPtr)
}

if ($found !== $expected) {
$error = 'Expected %s space(s) after %s keyword; %s found';
$pluralizeSpace = 's';
if ($expected === 1) {
$pluralizeSpace = '';
}

$error = 'Expected %s space%s after %s keyword; %s found';
$data = [
$expected,
$pluralizeSpace,
strtoupper($tokens[$stackPtr]['content']),
$found,
];
Expand All @@ -120,7 +126,7 @@ public function process(File $phpcsFile, $stackPtr)
$phpcsFile->fixer->replaceToken(($stackPtr + 1), str_repeat(' ', $expected));
}
}
}
}//end if

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

if ($found !== $expected) {
$error = 'Expected %s space(s) after closing parenthesis; found %s';
$pluralizeSpace = 's';
if ($expected === 1) {
$pluralizeSpace = '';
}

$error = 'Expected %s space%s after closing parenthesis; found %s';
$data = [
$expected,
$pluralizeSpace,
$found,
];

Expand Down
Expand Up @@ -305,6 +305,17 @@ $r = match ($x) {

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

// @codingStandardsChangeSetting Squiz.ControlStructures.ControlSignature requiredSpacesBeforeColon 2
if ($a == 5):
echo "a equals 5";
echo "...";
elseif ($a == 6) :
echo "a equals 6";
echo "!!!";
else :
echo "a is neither 5 nor 6";
endif;

// Reset property.
// @codingStandardsChangeSetting Squiz.ControlStructures.ControlSignature requiredSpacesBeforeColon 1

Expand Down
Expand Up @@ -309,6 +309,17 @@ $r = match ($x) {
$r = match ($x) {
1 => 1};

// @codingStandardsChangeSetting Squiz.ControlStructures.ControlSignature requiredSpacesBeforeColon 2
if ($a == 5) :
echo "a equals 5";
echo "...";
elseif ($a == 6) :
echo "a equals 6";
echo "!!!";
else :
echo "a is neither 5 nor 6";
endif;

// Reset property.
// @codingStandardsChangeSetting Squiz.ControlStructures.ControlSignature requiredSpacesBeforeColon 1

Expand Down
Expand Up @@ -77,6 +77,8 @@ public function getErrorList($testFile='ControlSignatureUnitTest.inc')
$errors[279] = 1;
$errors[283] = 1;
$errors[306] = 3;
$errors[309] = 1;
$errors[315] = 1;
}//end if

return $errors;
Expand Down

0 comments on commit 5632363

Please sign in to comment.