You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would normally format anonymous classes like the following example:
<?phpnamespaceExample;
classExample
{
publicfunction__construct()
{
$this->foo(newclass {
publicfunctionbar()
{
}
}); // <-- New error message: "Closing class brace must be on a line by itself"
}
publicfunctionfoo($input)
{
}
}
There doesn't seem to be any way to solve this while still satisfying other rules. If I move the closing parenthesis onto the next line, I get error message "Expected 0 spaces before closing bracket; newline found".
The text was updated successfully, but these errors were encountered:
I'm happy with this as a workaround, but others might consider this a breaking change.
gsherwood
changed the title
Rule conflict for anonymous classes
PSR12.Classes.AnonClassDeclaration incorrectly enforcing that closing brace be on a line by itself
Nov 3, 2019
The reason for this is because the included PSR12 standard was only about 50% complete until 3.5.0, so you may have also noticed a lot more errors being generated.
This issue is caused by the reuse of the PSR2 sniff to help aid in class checking. I think PSR-12 just needs to ignore this specific error code, but I'll make sure it is still enforcing the closing brace placement rules that the anon class formatting is inheriting for closures.
This is now fixed and both those code snippets pass without error.
I made the change in the PSR2 sniff directly as PSR2 doesn't mention anon classes so it probably shouldn't be that strict about them there. That had the effect of fixing PSR12 as well.
There appears to be no accepted way to format anonymous classes. This broke between 3.4.2 and 3.5.1.
I am using the following ruleset:
I would normally format anonymous classes like the following example:
There doesn't seem to be any way to solve this while still satisfying other rules. If I move the closing parenthesis onto the next line, I get error message "Expected 0 spaces before closing bracket; newline found".
The text was updated successfully, but these errors were encountered: