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

10.2: EntityReferenceTestTrait to EntityReferenceFieldCreationTrait rector using RenameClassRector #272

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/drupal-10/drupal-10.2-deprecations.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use DrupalRector\Rector\ValueObject\FunctionToStaticConfiguration;
use DrupalRector\Rector\ValueObject\MethodToMethodWithCheckConfiguration;
use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Symfony\Set\SymfonySetList;

return static function (RectorConfig $rectorConfig): void {
Expand All @@ -24,4 +25,9 @@
new MethodToMethodWithCheckConfiguration('Drupal\system\Plugin\ImageToolkit\GDToolkit', 'getResource', 'getImage'),
new MethodToMethodWithCheckConfiguration('Drupal\system\Plugin\ImageToolkit\GDToolkit', 'setResource', 'setImage'),
]);

// https://www.drupal.org/node/3401941
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, [
'Drupal\\Tests\\field\\Traits\\EntityReferenceTestTrait' => 'Drupal\\Tests\\field\\Traits\\EntityReferenceFieldCreationTrait',
]);
Comment on lines +31 to +34
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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

};
9 changes: 9 additions & 0 deletions fixtures/d10/rector_examples/entity_reference_trait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

use Drupal\Tests\field\Traits\EntityReferenceTestTrait;

class EntityReferenceItemTest extends FieldKernelTestBase {

use EntityReferenceTestTrait;

}
10 changes: 10 additions & 0 deletions fixtures/d10/rector_examples_updated/entity_reference_trait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

use Drupal\Tests\field\Traits\EntityReferenceFieldCreationTrait;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;

class EntityReferenceItemTest extends FieldKernelTestBase {

use EntityReferenceFieldCreationTrait;

}
Loading