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

PSR12/AnonClassDeclaration: prevent fixer creating parse error #56

Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ The file documents changes to the PHP_CodeSniffer project.
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Fixed bug #3789 : Incorrect tokenization for ternary operator with match inside of it
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Fixed bug #3790 : PSR12/AnonClassDeclaration: prevent fixer creating parse error when there was no space before the open brace
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Fixed bug #3797 : Tokenizer/PHP: more context sensitive keyword fixes
- Thanks to Juliette Reinders Folmer (@jrfnl) for the patch
- Fixed bug #3801 : File::getMethodParameters(): allow for readonly promoted properties without visibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ public function process(File $phpcsFile, $stackPtr)
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr, true);
$indent = str_repeat(' ', ($tokens[$first]['column'] - 1));
$phpcsFile->fixer->beginChangeset();
$phpcsFile->fixer->replaceToken(($prev + 1), '');

if ($tokens[($prev + 1)]['code'] === \T_WHITESPACE) {
$phpcsFile->fixer->replaceToken(($prev + 1), '');
}

$phpcsFile->fixer->addNewline($prev);
$phpcsFile->fixer->addContentBefore($opener, $indent);
$phpcsFile->fixer->endChangeset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,9 @@ $foo->bar(

foo(new class {
});

// Issue #3790: OpenBraceSameLine fixer should not remove open brace.
$instance = new class() extends SomeClass implements
SomeInterface{
public function __construct() {}
};
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,10 @@ $foo->bar(

foo(new class {
});

// Issue #3790: OpenBraceSameLine fixer should not remove open brace.
$instance = new class () extends SomeClass implements
SomeInterface
{
public function __construct() {}
};
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public function getErrorList()
56 => 2,
63 => 1,
75 => 1,
87 => 1,
88 => 1,
];

}//end getErrorList()
Expand Down