Skip to content

Commit 1f3ed76

Browse files
committed
Fix fixer conflict: PSR12/Squiz.Functions.FunctionDeclarationArgumentSpacing
1 parent 92c8ef5 commit 1f3ed76

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,26 +235,36 @@ public function processBracket($phpcsFile, $openBracket)
235235
if ($param['type_hint_token'] !== false) {
236236
$typeHintToken = $param['type_hint_end_token'];
237237

238-
$gap = 0;
239-
if ($tokens[($typeHintToken + 1)]['code'] === T_WHITESPACE) {
240-
$gap = $tokens[($typeHintToken + 1)]['length'];
238+
$gap = '';
239+
$i = $typeHintToken;
240+
while ($tokens[++$i]['code'] === T_WHITESPACE) {
241+
$gap .= $tokens[$i]['content'];
241242
}
242243

243-
if ($gap !== 1) {
244+
if ($gap !== ' ') {
244245
$error = 'Expected 1 space between type hint and argument "%s"; %s found';
245246
$data = [
246247
$param['name'],
247248
$gap,
248249
];
249250
$fix = $phpcsFile->addFixableError($error, $typeHintToken, 'SpacingAfterHint', $data);
250251
if ($fix === true) {
251-
if ($gap === 0) {
252-
$phpcsFile->fixer->addContent($typeHintToken, ' ');
252+
$phpcsFile->fixer->beginChangeset();
253+
$i = $typeHintToken;
254+
255+
if ($tokens[($i + 1)]['code'] === T_WHITESPACE) {
256+
$phpcsFile->fixer->replaceToken(++$i, ' ');
253257
} else {
254-
$phpcsFile->fixer->replaceToken(($typeHintToken + 1), ' ');
258+
$phpcsFile->fixer->addContent($typeHintToken, ' ');
255259
}
260+
261+
while ($tokens[++$i]['code'] === T_WHITESPACE) {
262+
$phpcsFile->fixer->replaceToken($i, '');
263+
}
264+
265+
$phpcsFile->fixer->endChangeset();
256266
}
257-
}
267+
}//end if
258268
}//end if
259269

260270
$commaToken = false;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,7 @@ $a = function ($var1, $var2=false) use (
109109
) {};
110110

111111
fn ($a,$b = null) => $a($b);
112+
113+
public function newlineAfterType(int
114+
$number)
115+
{}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,6 @@ $a = function ($var1, $var2=false) use (
109109
) {};
110110

111111
fn ($a, $b=null) => $a($b);
112+
113+
public function newlineAfterType(int $number)
114+
{}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function getErrorList()
6868
106 => 1,
6969
107 => 2,
7070
111 => 3,
71+
113 => 1,
7172
];
7273

7374
}//end getErrorList()

0 commit comments

Comments
 (0)