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

Fix EntityManagerRector based on project_analysis results #274

Merged
merged 10 commits into from
Dec 5, 2023

Conversation

bbrala
Copy link
Collaborator

@bbrala bbrala commented Nov 26, 2023

Description

Explain the technical implementation of the work done.

To Test

  • Add steps to test this feature

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.

@bbrala
Copy link
Collaborator Author

bbrala commented Nov 26, 2023

Fixes 220 error while running analysis.

Search for vendor/palantirnet/drupal-rector/src/Drupal8/Rector/Deprecation/EntityM

In https://git.drupalcode.org/project/project_analysis/-/commits/11-55227?ref_type=tags

@bbrala bbrala marked this pull request as draft November 26, 2023 10:59
@bbrala
Copy link
Collaborator Author

bbrala commented Nov 26, 2023

Marked draft, needs better solution.

@bbrala
Copy link
Collaborator Author

bbrala commented Nov 26, 2023

Copied a functional test locally, which shows the difference. Will push tonight.

@bbrala bbrala marked this pull request as ready for review November 26, 2023 20:12
@bbrala
Copy link
Collaborator Author

bbrala commented Nov 26, 2023

Ok, only error i made was mostly the removal of the depth counter. Also made phpstan a little more happy. Ready for review. Should solve lots of errors in project anlysis

@bbrala bbrala force-pushed the bug/entitymanagerrector branch from 0c9acfb to bb3284c Compare December 2, 2023 11:25
@bbrala bbrala force-pushed the bug/entitymanagerrector branch from bb3284c to 5a2340f Compare December 2, 2023 17:13
Copy link
Collaborator

@mglaman mglaman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notes, I think we can tidy up some of the checks.

Comment on lines 150 to +151
// Should the expression be the class we are looking for and the name is the one we are looking for, we can return early.
if ($node instanceof $class && $this->getName($node->name) === $name) {
if ($node instanceof Node && $node instanceof $class && $this->getName($node->name) === $name) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expr is nullable? It's not supposed to be

$node = $node->var;
++$depth;
if ($node instanceof $class && $this->getName($node->name)) {

if ($node instanceof Node && $node instanceof $class && isset($node->name) && $this->getName($node->name)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, feels weird that we have to instanceof something which shouldn't be nullable and is \PhpParser\Node\Expr

And we can call $this->getName($node), that's what the name resolver is for.

Comment on lines -155 to +158
while (isset($node->var) && !($node->var instanceof $class && $this->getName($node->var->name) !== $name)) {
while (isset($node->var) && !($node->var instanceof $class && isset($node->var->name) && $this->getName($node->var->name) !== $name)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this work if we did $this->getName($node->var)? See \Rector\NodeNameResolver\NodeNameResolver\VariableNameResolver::resolve

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this, it makes the functional tests fail :(


public function provideConfigFilePath(): string
{
// must be implemented
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it has?

use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
// $rectorConfig->rule(EntityViewRector::class);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove this?

@bbrala
Copy link
Collaborator Author

bbrala commented Dec 4, 2023

I tried to use getName properly, but couldnt get unit and functional tests to work :(

(small tip: brew install act, then remove the unneeded matrix definitions and run: act push -W ./.github/workflows/functional_test__rector_examples.yml, functional test locally <3)

Copy link
Collaborator

@mglaman mglaman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, too much work to make it fancy :)

@bbrala bbrala merged commit eab4674 into main Dec 5, 2023
7 checks passed
@bbrala bbrala changed the title Found a bug while going through the d11 run on project analysis Fix EntityManagerRector based on project_analysis results Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants