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

[DeadCode] Skip clone and new self on RemoveUnusedPrivatePropertyRector #1215

Merged
merged 11 commits into from Nov 12, 2021

Conversation

samsonasik
Copy link
Member

Given the following code:

class SkipCloneSelf
{
    private $var;

    public function __construct($var)
    {
        $this->var = $var;
    }

    public function run()
    {
        $obj = clone $this;
        echo $obj->var;
    }

    public function run2($var)
    {
        $obj = new self($var);
        echo $obj->var;
    }
}

It produce:

-    private $var;
-
-    public function __construct($var)
+    public function __construct()
     {
-        $this->var = $var;
     }

which should be skipped, ref https://3v4l.org/jjNe3

@samsonasik
Copy link
Member Author

Fixed 🎉

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba it is ready for review.

}
}

private function isPropertyNameInNewCurrentClassNameSelfClone(string $propertyName, ?ClassLike $classLike): bool
Copy link
Member

Choose a reason for hiding this comment

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

Could you extract this to own service? The logic seems quite complex

Copy link
Member Author

Choose a reason for hiding this comment

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

implemented, I moved to new service ForbiddenPropertyRemovalAnalyzer 12bf694

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba I think it is ready.

@TomasVotruba TomasVotruba merged commit 19d01b9 into main Nov 12, 2021
@TomasVotruba TomasVotruba deleted the skip-clone-self branch November 12, 2021 13:27
@TomasVotruba
Copy link
Member

Thank you 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants