Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fixer conflict: PSR12 / Squiz.Functions.FunctionDeclarationArgumentSpacing #620

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -235,26 +235,36 @@ public function processBracket($phpcsFile, $openBracket)
if ($param['type_hint_token'] !== false) {
$typeHintToken = $param['type_hint_end_token'];

$gap = 0;
if ($tokens[($typeHintToken + 1)]['code'] === T_WHITESPACE) {
$gap = $tokens[($typeHintToken + 1)]['length'];
$gap = '';
$i = $typeHintToken;
while ($tokens[++$i]['code'] === T_WHITESPACE) {
$gap .= $tokens[$i]['content'];
}

if ($gap !== 1) {
if ($gap !== ' ') {
$error = 'Expected 1 space between type hint and argument "%s"; %s found';
$data = [
$param['name'],
$gap,
];
$fix = $phpcsFile->addFixableError($error, $typeHintToken, 'SpacingAfterHint', $data);
if ($fix === true) {
if ($gap === 0) {
$phpcsFile->fixer->addContent($typeHintToken, ' ');
$phpcsFile->fixer->beginChangeset();
$i = $typeHintToken;

if ($tokens[($i + 1)]['code'] === T_WHITESPACE) {
$phpcsFile->fixer->replaceToken(++$i, ' ');
} else {
$phpcsFile->fixer->replaceToken(($typeHintToken + 1), ' ');
$phpcsFile->fixer->addContent($typeHintToken, ' ');
}

while ($tokens[++$i]['code'] === T_WHITESPACE) {
$phpcsFile->fixer->replaceToken($i, '');
}

$phpcsFile->fixer->endChangeset();
}
}
}//end if
}//end if

$commaToken = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,7 @@ $a = function ($var1, $var2=false) use (
) {};

fn ($a,$b = null) => $a($b);

public function newlineAfterType(int
$number)
{}
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,6 @@ $a = function ($var1, $var2=false) use (
) {};

fn ($a, $b=null) => $a($b);

public function newlineAfterType(int $number)
{}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function getErrorList()
106 => 1,
107 => 2,
111 => 3,
113 => 1,
];

}//end getErrorList()
Expand Down