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
NewWithBracesFixer - option to remove braces #5892
NewWithBracesFixer - option to remove braces #5892
Conversation
I belive the parentheses MUST be present even for anonymous classes and the PSR-12 should receive an errata :) The parentheses stress that a constructor is called and even needed when one or more arguments need to be passed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given this comment: php-fig/fig-standards#1206 (review) I'd vote to reject this proposl.
@mvorisek @kubawerlos @keradus Thank you for linking to this discussion in php-fig, I wasn't aware of that. Would you be OK with adding these options without changing the PSR-12 rule set configuration then? |
If the changes are not following PSR12 (even if the spec was confusing and cannot be amended now because of reasons) than these should be coming from some other standard and/or supported/used by a bigger PHP community (this is a requirement for any rule or option). |
@SpacePossum I think Laravel does not use parentheses when there are no arguments, although I'm not sure whether it's a formal rule or they just use them randomly. |
24371e0
to
16b2c72
Compare
Sorry for force pushing, didn't know fabbot doesn't like merge commits. |
@GrahamCampbell do you know if this CS is part of the style of laravel? |
Laravel doesn't use this fixer, or particularly care about the code style here. There is no interest from the Laravel core team to normalize the code style in either direction, as far as I'm aware. |
16b2c72
to
ef66dc4
Compare
ef66dc4
to
2282dad
Compare
Thanks Graham. As this is not part of style defined by a popular standard or used in a bigger (F)OSS project I'm not in favor of adding this feature, I think a 3rd party fixer would be a better fit. (also, would be better to utilize |
@SpacePossum After seeing this comment by @sebastianbergmann, I think PHPUnit may be interested in using these options. |
6cc6ef4
to
f2d0e89
Compare
The |
56a33a7
to
85c0c4d
Compare
85c0c4d
to
e776072
Compare
I lack the expertise to comment on its implementation, but I would like to be able to use this fixer in my projects. |
d6c000e
to
a2b325f
Compare
a2b325f
to
877624a
Compare
Thank you @jrmajor. |
Although PSR-12 states that “when instantiating a new class, parentheses MUST always be present”, this rule clearly does not apply to anonymous classes, as there are three examples of anonymous classes in PSR-12 and none of them has parentheses.This PR adds
named_class
andanonymous_class
boolean options toNewWithBracesFixer
. By default, both of them are set to true, which matches current behavior.However, I've changed the configuration in PSR-12 to['anonymous_class' => false]
, as this is the code style used in all examples.