Skip to content

Commit 3591d46

Browse files
committed
SlevomatCodingStandard.Whitespaces.DuplicateSpaces: Fixed false positive
1 parent 08e7989 commit 3591d46

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

SlevomatCodingStandard/Sniffs/Whitespaces/DuplicateSpacesSniff.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
use function preg_replace;
1414
use function sprintf;
1515
use const PREG_OFFSET_CAPTURE;
16+
use const T_BITWISE_AND;
1617
use const T_DOC_COMMENT_CLOSE_TAG;
1718
use const T_DOC_COMMENT_OPEN_TAG;
1819
use const T_DOC_COMMENT_STAR;
1920
use const T_DOC_COMMENT_STRING;
2021
use const T_DOC_COMMENT_TAG;
2122
use const T_DOC_COMMENT_WHITESPACE;
23+
use const T_ELLIPSIS;
2224
use const T_MATCH_ARROW;
2325
use const T_VARIABLE;
2426
use const T_WHITESPACE;
@@ -77,12 +79,18 @@ public function process(File $phpcsFile, int $whitespacePointer): void
7779

7880
if ($this->ignoreSpacesInParameters) {
7981
$pointerAfter = TokenHelper::findNextNonWhitespace($phpcsFile, $whitespacePointer + 1);
80-
if (
81-
$pointerAfter !== null
82-
&& $tokens[$pointerAfter]['code'] === T_VARIABLE
83-
&& ParameterHelper::isParameter($phpcsFile, $pointerAfter)
84-
) {
85-
return;
82+
if ($pointerAfter !== null) {
83+
if (in_array($tokens[$pointerAfter]['code'], [T_BITWISE_AND, T_ELLIPSIS], true)) {
84+
$pointerAfter = TokenHelper::findNextNonWhitespace($phpcsFile, $pointerAfter + 1);
85+
}
86+
87+
if (
88+
$pointerAfter !== null
89+
&& $tokens[$pointerAfter]['code'] === T_VARIABLE
90+
&& ParameterHelper::isParameter($phpcsFile, $pointerAfter)
91+
) {
92+
return;
93+
}
8694
}
8795
}
8896

tests/Sniffs/Whitespaces/data/duplicateSpacesIgnoreSpacesInParametersNoErrors.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
function doSomething(
44
string $a,
5-
int $b
5+
int $b,
6+
int &$c,
7+
int ...$d
68
) {
79

810
}

0 commit comments

Comments
 (0)