Drupal version
Not in yet
MR on Github
https://github.com/palantirnet/drupal-rector/pull/308
Drupal Rector version
Not in yet
Problem / Motivation
When #3442009: OOP hooks using attributes and event dispatcher lands it would be nice to have a rector rule to convert the procedural hooks into OOP attributes.
I've moved the rule @ghostofdrupalpast wrote to the PR.
I need some advice on how to include this more properly as for now for testing I've just replaced all rules with only this rule.
This is probably fine for a one time or per module run for core. Once core deprecates procedural hooks we can move this to a normal deprecation.
This does need some work from #3461148: Drupal.WhiteSpace.ScopeIndent gets confused by attributes on a function. as well, if you look at the gist below you can see there are still some spacing issues: https://gitlab.com/-/snippets/3759543
Specifically look at the indentation of the function declarations after the attribute.
Also note that the attributes are fully expanded.
Issue fork rector-3481215
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
nicxvan commentedFor local testing @bbrala mentioned this in slack:
The test structure has a configured rule file which configures which rules to run. Check out the other tests for the structure. This is the same default structure as rector has itself.
For locally, you could copy the default rector.php file and remove the sets and only add your rule.
Comment #3
nicxvan commentedI'm having trouble running this locally against announcements_feed.
I am running this:
Here is a draft pr: https://github.com/palantirnet/drupal-rector/pull/308/files
Locally I commented out the other rules just to test this one.
I just get this:
Comment #4
nicxvan commentedOk I got this working with the PR here:
I need some advice on how to include this since it's not a deprecation yet, we can use this just for core for now.
My Draft comments out all of the drupal deprecations just for the hook convert rule.
I had to read the README here: https://github.com/palantirnet/drupal-rector-sandbox
How I got this working locally in ddev:
First require drupal-rector
ddev composer require --dev palantirnet/drupal-rector
I then copied my changes from the PR: https://github.com/palantirnet/drupal-rector/pull/308/file
Create rector web command in ddev:
Run
ddev rectorCreate codefix command in ddev:
See output:
https://gitlab.com/-/snippets/3759543
Comment #5
nicxvan commentedComment #6
nicxvan commentedComment #7
nicxvan commentedYou can also see a more full test against the user module here: #3481582: [ignore] Convert User module and submodules to use OOP hooks.
Comment #8
nicxvan commentedYou can also run ddev composer phpcbf
Comment #9
nicxvan commentedI could use some advice on how to inject this as a separate convert command for core.
We will likely want to add this for contrib too once procedural hooks are deprecated, but we have some time for that.
It's obviously not ready for merging, but it's probably close enough for an approach review.
There are several warnings in the rule that I can look at separately.
Comment #10
bbralaComment #11
nicxvan commentedThanks for taking a look, the extra changes were so I could run it locally until I got your advice.
If you want to see it run against the user module you can see it here: https://git.drupalcode.org/project/drupal/-/merge_requests/9890/diffs
Comment #12
joachim commentedShould this be closed? The PR at https://github.com/palantirnet/drupal-rector/pull/308 says it's been merged.
Comment #13
bbralaYou're right! Thanks