-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feature: Add support for custom method placement in ordered_class_elements
#6360
feature: Add support for custom method placement in ordered_class_elements
#6360
Conversation
Thank you @bakerkretzmar 🙌 |
@keradus @SpacePossum @gharlan anything else you need from me here? |
ordered_class_elements
ordered_class_elements
ordered_class_elements
ordered_class_elements
Thanks, @bakerkretzmar for updating this! |
@bakerkretzmar I wanted to rebase it in order to process it further on latest |
@Wirone thanks! I did update the docs by hand, I had no idea PHP-CS-Fixer/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php Lines 209 to 238 in c1470f1
PHP-CS-Fixer/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php Lines 373 to 398 in c1470f1
PHP-CS-Fixer/src/Fixer/Import/OrderedImportsFixer.php Lines 260 to 282 in c1470f1
How are those ones documented? |
I don't know if it existed back then, so no worry. That's why I try to introduce some common scripts and improve contributing guide, because I see that not everything is obvious (for me too) 🙂. In terms of allowed values probably we need to include info about |
Before we think how, let's discuss if we should do it at all, see #3864 (comment). |
Closing/reopening to trigger CI. |
@kubawerlos I don't see negative sides of this approach (besides slightly higher complexity to maintain). There's no any "injecting code", only fixed implementation that allows better flexibility of how users want to order methods in a class. It's option like the others, but supports dynamic values - however those values have to be in subset defined by class itself. I believe there are valid scenarios for that 🙂. |
@Wirone oh, I see now, I understood the docs part:
as there would be possible to use that method to sort class elements, assuming the doc was generated from code, which apparently is not the case here. There is no way to achieve that now - it's either a fixed list of strings or any string. One way to go would be to deprecate the current option and create a new one, where all current options would have [
'#method_protected_static',
'MyClass::myMethod',
'#method_protected',
'#magic'
] SRP for the win - let's split it anyway and add |
@kubawerlos that's an interesting idea! I'd like to keep the scope of this PR very focused, so I'm not going to update it to deprecate the current options—my proposal here is only to add a new @Wirone can this particular fixer just be documented by hand? Let me know if there's anything I need to do here! |
Co-authored-by: driftingly <driftingly@users.noreply.github.com>
a275d60
to
8cb82c2
Compare
No, because it will be overridden by script when it' used. We need to use description for that, so script would take it always the same way. And it won't pass auto-review tests, which use the same mechanism as |
@Wirone thanks! I moved things into the description, the documentation script should work now. |
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.
👍 from me, good job @bakerkretzmar. I won't merge it, though, let's wait for another review.
Thank you @bakerkretzmar and welcome to the Fixer's contributors group 😁🍻. |
Thanks!! Really appreciate all the feedback on this and glad we're going to be able to use it soon 🔨 🔧 |
As discussed in #6244, this PR adds the ability to place specific individual methods in a custom order within a class.
The original PR was to add a custom
invoke
option similar toconstruct
, to place the__invoke()
method at a custom location instead of grouping it with other magic methods. After some discussion with @SpacePossum @gharlan and @driftingly it sounded like a more generic solution would be preferred, to allow placing any specific method at a custom location, not just__invoke()
.The suggestion from that discussion was to allow
['method' => 'methodName']
in the list of options to specify custom orders. I chose to usemethod:methodName
instead because the code changes are a lot simpler and smaller if all the options are still plain strings.method:
options override any other ordering, so for examplemethod:__invoke
takes precedence overmagic
.In the future it would probably be quite straightforward to support specific properties/constants/traits too with similar syntax (e.g.
property:propertyName
), although I'm not sure if that's useful.Replaces #6244
Closes #6252