Skip to content

Squiz/FunctionDeclarationArgumentSpacing: handle asym modifiers for constructor property promotion #1121

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

Merged
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 @@ -340,6 +340,40 @@ public function processBracket($phpcsFile, $openBracket)
}//end if
}//end if

if (isset($param['set_visibility_token']) === true && $param['set_visibility_token'] !== false) {
$visibilityToken = $param['set_visibility_token'];
$afterVisibilityToken = $phpcsFile->findNext(T_WHITESPACE, ($visibilityToken + 1), $param['token'], true);

$spacesAfter = 0;
if ($afterVisibilityToken !== false
&& $tokens[$visibilityToken]['line'] !== $tokens[$afterVisibilityToken]['line']
) {
$spacesAfter = 'newline';
} else if ($tokens[($visibilityToken + 1)]['code'] === T_WHITESPACE) {
$spacesAfter = $tokens[($visibilityToken + 1)]['length'];
}

if ($spacesAfter !== 1) {
$error = 'Expected 1 space after set-visibility modifier "%s"; %s found';
$data = [
$tokens[$visibilityToken]['content'],
$spacesAfter,
];

$fix = $phpcsFile->addFixableError($error, $visibilityToken, 'SpacingAfterSetVisbility', $data);
if ($fix === true) {
$phpcsFile->fixer->beginChangeset();
$phpcsFile->fixer->addContent($visibilityToken, ' ');

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

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

if (isset($param['readonly_token']) === true) {
$readonlyToken = $param['readonly_token'];
$afterReadonlyToken = $phpcsFile->findNext(T_WHITESPACE, ($readonlyToken + 1), $param['token'], true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,18 @@ class PropertyPromotionSpacingAfterModifier {
string $tooMuchSpaceNewLines,
) {}
}

class AsymVisibilityPropertyPromotionSpacingAfterComma {
public function __construct(private(set) string|int $propA, protected(set) bool $correctSpace, public(set) MyClass $tooMuchSpace,public(set) string $noSpace) {}
}

class AsymVisibilityPropertyPromotionSpacingAfterModifier {
public function __construct(
private(set)$noSpace,
public(set) MyClass $tooMuchSpace,
protected(set) public string $tooMuchSpaceX2,
private
public(set)
string $tooMuchSpaceNewLines,
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,16 @@ class PropertyPromotionSpacingAfterModifier {
readonly public string $tooMuchSpaceNewLines,
) {}
}

class AsymVisibilityPropertyPromotionSpacingAfterComma {
public function __construct(private(set) string|int $propA, protected(set) bool $correctSpace, public(set) MyClass $tooMuchSpace, public(set) string $noSpace) {}
}

class AsymVisibilityPropertyPromotionSpacingAfterModifier {
public function __construct(
private(set) $noSpace,
public(set) MyClass $tooMuchSpace,
protected(set) public string $tooMuchSpaceX2,
private public(set) string $tooMuchSpaceNewLines,
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ public function getErrorList($testFile='')
207 => 2,
208 => 1,
209 => 1,
215 => 2,
220 => 1,
221 => 1,
222 => 2,
223 => 1,
224 => 1,
];

default:
Expand Down