AddOverrideAttributeToOverriddenMethodsRector
is not compatible with PHPStan's checkMissingOverrideMethodAttribute
rule
#9068
Labels
Bug Report
First of all, thanks for this amazing project ❤
For a while now I noticed that Rector did not add Override attributes anymore, while PHPStan complained.
Today I looked into it and it turns out it's related to this change:
It states the following:
I don't agree with this. I think the reason for using the Override attribute is exactly this. To indicate that you implement/override a method coming from a parent (class or interface). Whenever that method is removed there, it should error on the implementation, indicating that the thing you thought you were doing no longer has any impact.
https://wiki.php.net/rfc/marking_overriden_methods
This rule conflicts with PHPStan's
checkMissingOverrideMethodAttribute
rule.For example, I'm currently working on a Symfony Console Command:
And
AddOverrideAttributeToOverriddenMethodsRector
does not add the#[Override]
attributes to the configure and execute methods.This produces the following PHPStan errors:
When I comment this out:
https://github.com/rectorphp/rector-src/blob/217026caf877c60eb7a7fd61b5b16d9a642f1662/rules/Php83/Rector/ClassMethod/AddOverrideAttributeToOverriddenMethodsRector.php#L225-L243
Rector does successfully add the
Override
attributes and the errors go away./cc @TomasVotruba @samsonasik
The text was updated successfully, but these errors were encountered: