Skip to content

Commit 1700601

Browse files
committed
Squiz/FunctionDeclarationArgumentSpacing: bug fix / SpacingAfterVariadic does not flag new lines
A `T_WHITESPACE` token only containing new line characters will have its token `'length'` set to `0`. This means that if there was a new line after an ellipsis token, the sniff would not report it. Fixed now. Also note that, as the sniff demands no whitespace after a reference operator, we don't need the extra check for `$gap !== 0` as we already know that the next token is a whitespace token and needs to be flagged. Includes test.
1 parent 30319c4 commit 1700601

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

src/Standards/Squiz/Sniffs/Functions/FunctionDeclarationArgumentSpacingSniff.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,12 @@ public function processBracket($phpcsFile, $openBracket)
175175
if ($param['variable_length'] === true) {
176176
$variadicToken = $param['variadic_token'];
177177

178-
$gap = 0;
179178
if ($tokens[($variadicToken + 1)]['code'] === T_WHITESPACE) {
180179
$gap = $tokens[($variadicToken + 1)]['length'];
181-
}
180+
if ($tokens[$variadicToken]['line'] !== $tokens[($variadicToken + 2)]['line']) {
181+
$gap = 'newline';
182+
}
182183

183-
if ($gap !== 0) {
184184
$error = 'Expected 0 spaces after variadic operator for argument "%s"; %s found';
185185
$data = [
186186
$param['name'],

src/Standards/Squiz/Tests/Functions/FunctionDeclarationArgumentSpacingUnitTest.inc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,15 @@ function newlineAfterReferenceFixerRespectsComment(
130130
// comment
131131
$param
132132
) {}
133+
134+
function newlineAfterVariadicShouldBeFlaggedAndFixed(
135+
...
136+
137+
$param
138+
) {}
139+
140+
function newlineAfterVariadicFixerRespectsComment(
141+
...
142+
//comment
143+
$param
144+
) {}

src/Standards/Squiz/Tests/Functions/FunctionDeclarationArgumentSpacingUnitTest.inc.fixed

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,12 @@ function newlineAfterReferenceFixerRespectsComment(
122122
&// comment
123123
$param
124124
) {}
125+
126+
function newlineAfterVariadicShouldBeFlaggedAndFixed(
127+
...$param
128+
) {}
129+
130+
function newlineAfterVariadicFixerRespectsComment(
131+
...//comment
132+
$param
133+
) {}

src/Standards/Squiz/Tests/Functions/FunctionDeclarationArgumentSpacingUnitTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public function getErrorList()
7272
117 => 1,
7373
123 => 1,
7474
129 => 1,
75+
135 => 1,
76+
141 => 1,
7577
];
7678

7779
}//end getErrorList()

0 commit comments

Comments
 (0)