Skip to content

Commit d46210e

Browse files
DannyvdSluijsjrfnl
authored andcommitted
Various sniffs: fix grammar for various error messages
Correct pluralization of the word space/spaces depending on the spacing value. For these sniffs, the changes are already covered by pre-existing tests. Port squizlabs/PHP_CodeSniffer 3881 to this repo
1 parent f83010f commit d46210e

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

src/Standards/Generic/Sniffs/Formatting/SpaceAfterCastSniff.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ public function register()
5454
*/
5555
public function process(File $phpcsFile, $stackPtr)
5656
{
57-
$tokens = $phpcsFile->getTokens();
58-
$this->spacing = (int) $this->spacing;
57+
$tokens = $phpcsFile->getTokens();
58+
$this->spacing = (int) $this->spacing;
59+
$pluralizeSpace = 's';
60+
if ($this->spacing === 1) {
61+
$pluralizeSpace = '';
62+
}
5963

6064
if ($tokens[$stackPtr]['code'] === T_BINARY_CAST
6165
&& $tokens[$stackPtr]['content'] === 'b'
@@ -83,8 +87,11 @@ public function process(File $phpcsFile, $stackPtr)
8387

8488
$nextNonWhitespace = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
8589
if ($nextNonEmpty !== $nextNonWhitespace) {
86-
$error = 'Expected %s space(s) after cast statement; comment found';
87-
$data = [$this->spacing];
90+
$error = 'Expected %s space%s after cast statement; comment found';
91+
$data = [
92+
$this->spacing,
93+
$pluralizeSpace,
94+
];
8895
$phpcsFile->addError($error, $stackPtr, 'CommentFound', $data);
8996

9097
if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) {
@@ -109,9 +116,10 @@ public function process(File $phpcsFile, $stackPtr)
109116
return;
110117
}
111118

112-
$error = 'Expected %s space(s) after cast statement; %s found';
119+
$error = 'Expected %s space%s after cast statement; %s found';
113120
$data = [
114121
$this->spacing,
122+
$pluralizeSpace,
115123
$found,
116124
];
117125

src/Standards/Generic/Sniffs/Formatting/SpaceAfterNotSniff.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ public function register()
6464
*/
6565
public function process(File $phpcsFile, $stackPtr)
6666
{
67-
$tokens = $phpcsFile->getTokens();
68-
$this->spacing = (int) $this->spacing;
67+
$tokens = $phpcsFile->getTokens();
68+
$this->spacing = (int) $this->spacing;
69+
$pluralizeSpace = 's';
70+
if ($this->spacing === 1) {
71+
$pluralizeSpace = '';
72+
}
6973

7074
$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
7175
if ($nextNonEmpty === false) {
@@ -84,8 +88,11 @@ public function process(File $phpcsFile, $stackPtr)
8488

8589
$nextNonWhitespace = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
8690
if ($nextNonEmpty !== $nextNonWhitespace) {
87-
$error = 'Expected %s space(s) after NOT operator; comment found';
88-
$data = [$this->spacing];
91+
$error = 'Expected %s space%s after NOT operator; comment found';
92+
$data = [
93+
$this->spacing,
94+
$pluralizeSpace,
95+
];
8996
$phpcsFile->addError($error, $stackPtr, 'CommentFound', $data);
9097
return;
9198
}
@@ -101,9 +108,10 @@ public function process(File $phpcsFile, $stackPtr)
101108
return;
102109
}
103110

104-
$error = 'Expected %s space(s) after NOT operator; %s found';
111+
$error = 'Expected %s space%s after NOT operator; %s found';
105112
$data = [
106113
$this->spacing,
114+
$pluralizeSpace,
107115
$found,
108116
];
109117

src/Standards/Squiz/Sniffs/Commenting/DocCommentAlignmentSniff.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,15 @@ public function process(File $phpcsFile, $stackPtr)
112112
}
113113

114114
if ($tokens[$i]['column'] !== $requiredColumn) {
115-
$error = 'Expected %s space(s) before asterisk; %s found';
115+
$pluralizeSpace = 's';
116+
if (($requiredColumn - 1) === 1) {
117+
$pluralizeSpace = '';
118+
}
119+
120+
$error = 'Expected %s space%s before asterisk; %s found';
116121
$data = [
117122
($requiredColumn - 1),
123+
$pluralizeSpace,
118124
($tokens[$i]['column'] - 1),
119125
];
120126
$fix = $phpcsFile->addFixableError($error, $i, 'SpaceBeforeStar', $data);
@@ -126,7 +132,7 @@ public function process(File $phpcsFile, $stackPtr)
126132
$phpcsFile->fixer->replaceToken(($i - 1), $padding);
127133
}
128134
}
129-
}
135+
}//end if
130136

131137
if ($tokens[$i]['code'] !== T_DOC_COMMENT_STAR) {
132138
continue;

0 commit comments

Comments
 (0)