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

SingleLineThrowFixer - fix handling anonymous classes #5593

Merged
merged 1 commit into from Apr 22, 2021
Merged

SingleLineThrowFixer - fix handling anonymous classes #5593

merged 1 commit into from Apr 22, 2021

Conversation

kubawerlos
Copy link
Contributor

@kubawerlos kubawerlos commented Apr 5, 2021

Is this a right solution or SingleLineThrowFixer should not remove new lines from anonymous class definition?

Ping @nicolas-grekas for an opinion (as you are the person who originally requested this fixer).

@coveralls
Copy link

coveralls commented Apr 5, 2021

Coverage Status

Coverage remained the same at 91.902% when pulling c73f60a on kubawerlos:fix_SingleLineThrowFixer into 57c52b6 on FriendsOfPHP:2.18.

@nicolas-grekas
Copy link

nicolas-grekas commented Apr 5, 2021

I can't review the logic as I'm not into php-cs-fixer much but I think the target is nice, thanks for working on this!

@kubawerlos
Copy link
Contributor Author

@nicolas-grekas I am interested on your opinion from a user perspective - what should happen to this code:

throw
    new class()
        extends Exception
        {
            protected $message = "Custom message";
        }
     ;

Fully single line:

throw new class() extends Exception { protected $message = "Custom message"; };

or without class body:

throw new class() extends Exception
        {
            protected $message = "Custom message";
        };

?

@kubawerlos kubawerlos added this to the 2.18.6 milestone Apr 12, 2021
@keradus keradus removed this from the 2.18.6 milestone Apr 14, 2021

if (\PHP_VERSION_ID >= 70000) {
yield [
'<?php throw new class() extends Exception { protected $message = "Custom message"; };',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it can be pretty long
can we, easily, achieve that throw new class() extends Exception is enforced to be a single line, and the body of class is formatted properly by braces fixer?
if not, let's skill formatting of anonymous classes by single_line_throw, imho

@keradus
Copy link
Member

keradus commented Apr 22, 2021

Thank you @kubawerlos.

@keradus keradus merged commit 4353039 into PHP-CS-Fixer:2.18 Apr 22, 2021
@kubawerlos kubawerlos deleted the fix_SingleLineThrowFixer branch April 23, 2021 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants