Skip to content

Commit

Permalink
fix: Correct pluralization of the word space/spaces depending on the …
Browse files Browse the repository at this point in the history
…spacing value
  • Loading branch information
DannyvdSluijs committed Aug 31, 2023
1 parent a99c2d5 commit 5e03f11
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
16 changes: 14 additions & 2 deletions src/Standards/Generic/Sniffs/Arrays/ArrayIndentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,15 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
// check indent levels because it's not valid. But we don't enforce exactly
// how far indented it should be.
if ($startIndent < $baseIndent) {
$error = 'Array open brace not indented correctly; expected at least %s spaces but found %s';
$pluralizeSpace = 's';
if ($baseIndent === 1) {
$pluralizeSpace = '';
}

$error = 'Array open brace not indented correctly; expected at least %s space%s but found %s';
$data = [
$baseIndent,
$pluralizeSpace,
$startIndent,
];
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'OpenBraceIncorrect', $data);
Expand Down Expand Up @@ -117,9 +123,15 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
continue;
}

$error = 'Array key not indented correctly; expected %s spaces but found %s';
$pluralizeSpace = 's';
if ($expectedIndent === 1) {
$pluralizeSpace = '';
}

$error = 'Array key not indented correctly; expected %s space%s but found %s';
$data = [
$expectedIndent,
$pluralizeSpace,
$foundIndent,
];
$fix = $phpcsFile->addFixableError($error, $first, 'KeyIncorrect', $data);
Expand Down
16 changes: 11 additions & 5 deletions src/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -775,11 +775,17 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
}

if ($tokens[$indexPointer]['column'] !== $indicesStart && ($indexPointer - 1) !== $arrayStart) {
$expected = ($indicesStart - 1);
$found = ($tokens[$indexPointer]['column'] - 1);
$error = 'Array key not aligned correctly; expected %s spaces but found %s';
$data = [
$expected = ($indicesStart - 1);
$found = ($tokens[$indexPointer]['column'] - 1);
$pluralizeSpace = 's';
if ($expected === 1) {
$pluralizeSpace = '';
}

$error = 'Array key not aligned correctly; expected %s space%s but found %s';
$data = [
$expected,
$pluralizeSpace,
$found,
];

Expand All @@ -791,7 +797,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
$phpcsFile->fixer->replaceToken(($indexPointer - 1), str_repeat(' ', $expected));
}
}
}
}//end if

$arrowStart = ($tokens[$indexPointer]['column'] + $maxLength + 1);
if ($tokens[$index['arrow']]['column'] !== $arrowStart) {
Expand Down

0 comments on commit 5e03f11

Please sign in to comment.