Skip to content

Commit b0cb9c5

Browse files
authored
Merge pull request #48 from PHPCSStandards/feature/generic-spreadoperatorspacing-after-msg-improvement
Generic/SpreadOperatorSpacingAfter: minor message readability improvement
2 parents 45d33e0 + 511b877 commit b0cb9c5

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ The file documents changes to the PHP_CodeSniffer project.
8787
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
8888
- Tests using the PHPCS native test framework with multiple test case files will now run the test case files in numeric order.
8989
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
90+
- Generic/SpreadOperatorSpacingAfter: minor message readability improvement
91+
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
9092

9193
### Removed
9294
- Removed support for installing via PEAR

src/Standards/Generic/Sniffs/WhiteSpace/SpreadOperatorSpacingAfterSniff.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
$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
6165
if ($nextNonEmpty === false) {
@@ -81,8 +85,11 @@ public function process(File $phpcsFile, $stackPtr)
8185

8286
$nextNonWhitespace = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
8387
if ($nextNonEmpty !== $nextNonWhitespace) {
84-
$error = 'Expected %s space(s) after the spread operator; comment found';
85-
$data = [$this->spacing];
88+
$error = 'Expected %s space%s after the spread operator; comment found';
89+
$data = [
90+
$this->spacing,
91+
$pluralizeSpace,
92+
];
8693
$phpcsFile->addError($error, $stackPtr, 'CommentFound', $data);
8794

8895
if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) {
@@ -107,9 +114,10 @@ public function process(File $phpcsFile, $stackPtr)
107114
return;
108115
}
109116

110-
$error = 'Expected %s space(s) after the spread operator; %s found';
117+
$error = 'Expected %s space%s after the spread operator; %s found';
111118
$data = [
112119
$this->spacing,
120+
$pluralizeSpace,
113121
$found,
114122
];
115123

0 commit comments

Comments
 (0)