-
Notifications
You must be signed in to change notification settings - Fork 74
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
10.2: EntityReferenceTestTrait to EntityReferenceFieldCreationTrait rector using RenameClassRector #272
base: main
Are you sure you want to change the base?
Conversation
691d9fc
to
5e28aa5
Compare
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.
It's great we can use Rector\Renaming\Rector\Name\RenameClassRector
, however this will break anything <10.2.
The way Drupal core did this even broke contrib as it wasn't properly deprecated.
I don't even know the best way to handle this via Rector as it's a breaking change to use the new trait.
I've been looking into how i could use two traits, but the ways to do it are very very very very ugly. The sad thing is, the method could have been static...
We could do some magic with an added method and an anonimous class, which loads based on which class exists. Especially since that trait is not using the object context at all. Then it could be even backwards compatible. It just uses ugly code then. Somthings like
This might work, but the code is not very pretty. |
It'd probably be easier to add a class alias at the top of the class for the trait. |
I don't understand what you mean. |
Ok something like
But wrapped more sanely |
Ok, something like this should work.
Would probably not use the RenameClassRector but should use the service. That way renaming is easy, but we are targetting a trait right now, so might reduce the scope initially to keep it simple. Probably:
Few things im not sure about yet:
Also important: 10.2 was fixed in regards to keeping the old class see https://www.drupal.org/node/3403491 |
Yeah, like that. But only in tests using the trait – I have no idea how hard that makes it. Maybe target Class and then use PHPStan scope/tools to detect traits used.
Good Q. Maybe when D10 is EOL.
It should. See this abomination https://git.drupalcode.org/project/acquia_connector/-/blob/4.x/src/Event/EventBase.php?ref_type=heads |
Haha yeah I understand the code will work. But mostly if I can get rector to do it :) But I'll have a look, and perhaps we shouldn't care too much about forcing ^10.1 || ^11 in the modules. Although unneeded. |
All code that will be for 10.x deprecation will have that anyways, since deprecationhelper is only available since then. |
…using RenameClassRector. Fixes: https://www.drupal.org/node/3401941
…ot error, but is ugly. Can only be avoided if we start applying codestyle to the files. Which seem overkill. Although something like this could work maybe? rector-src/vendor/symplify/easy-coding-standard/config/set/common/namespaces.php
c61d2f4
to
945e35f
Compare
@mglaman I fixed the merge conflict here and tests pass locally. Could use another review. |
// https://www.drupal.org/node/3401941 | ||
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, [ | ||
'Drupal\\Tests\\field\\Traits\\EntityReferenceTestTrait' => 'Drupal\\Tests\\field\\Traits\\EntityReferenceFieldCreationTrait', | ||
]); |
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.
@bbrala should we wrap this with a BC protection? I guess then we'd need to extend RenameClassRector
and a config object to do so :/ or is there an easier way?
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.
Yeah we need to wrap. I've wanted to wrap for a few times now, but haven't taken the time to see if its ewasily possible.
You'd need to do quite a few weird things to make sure things are instantiated correctly. Would open up loads of easy things like this rector though.
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.
Since all classes in rector are final, there is no extending.
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.
I believe this PR is held up for the BC refactor?
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.
Yeah pretty much. Just feels like a lot of effort for 10.1 vs 10.2... Although the pattern might be usefull later.
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.
Ok, visited this again. Something generic is very hard. Something expanding on what RenameClassRector does AND hooking into the file is kinda hard.
So guess it needs a specific rector for this change, which is sad. And my time is up for today ;x
// https://www.drupal.org/node/3401941 | ||
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, [ | ||
'Drupal\\Tests\\field\\Traits\\EntityReferenceTestTrait' => 'Drupal\\Tests\\field\\Traits\\EntityReferenceFieldCreationTrait', | ||
]); |
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.
I believe this PR is held up for the BC refactor?
Description
Fixes: https://www.drupal.org/node/3401941
When renaming it does not remove the old use statement. This should not error, but is ugly.
Can only be avoided if we start applying codestyle to the files. Which seem overkill. Although something like this could work maybe? rector-src/vendor/symplify/easy-coding-standard/config/set/common/namespaces.php
To Test
Functional tests
Drupal.org issue
Provide a link to the issue from https://www.drupal.org/project/rector/issues. If no issue exists, please create one and link to this PR.