rector icon indicating copy to clipboard operation
rector copied to clipboard

Suggestion: remove #[Override] where no matching parent method exists.

Open mickverm opened this issue 1 year ago • 2 comments

Feature Request

https://3v4l.org/GNlaC https://getrector.com/demo/4fb89aa4-219b-4f41-84a3-e3fa2a0cf625

Diff

<?php

interface ParentInterface
{
    public function foo(): void;
}

final class ChildClass implements ParentInterface
{
    public function foo(): void
    {
        echo 'foo';
    }

-   #[\Override]
    public function bar(): void
    {
        echo 'bar';
    }
}

(new ChildClass())->bar();

mickverm avatar Dec 13 '24 13:12 mickverm

Never mind, this is something PHPStan already warns us about (fatal error).

mickverm avatar Dec 13 '24 13:12 mickverm

This would be great dead code rule though 👌

TomasVotruba avatar Dec 13 '24 16:12 TomasVotruba

I am thinking on the contrary, the fatal error is expected, when you have fatal error, you can immediatelly see there is BC break, and you can see the upgrade guide how to upgrade the child class correctly, eg: to use new method, then you see if you can use some configurable rector rule to upgrade it available, or create your own custom rector rule to upgrade to new method.

Removing the #[\Override] will cause silent check of available method in parent, make invalid change.

samsonasik avatar Jan 08 '25 03:01 samsonasik

Males sense, this would have to be handled by PHPStan.

TomasVotruba avatar Jan 08 '25 07:01 TomasVotruba

This issue has been automatically locked because it has been closed for 150 days. Please open a new issue if you have a similar problem.

github-actions[bot] avatar Dec 07 '25 03:12 github-actions[bot]