Skip to content

Rector is wrongly relying on ObjectType::equals implementation #9729

@VincentLanglet

Description

@VincentLanglet

Hi @TomasVotruba @samsonasik,

I'm currently working on a Fix in phpstan-src on ObjectType::equals (phpstan/phpstan-src#5399)

  • ObjectType->equals(GenericObjectType) was true (which is not correct)
  • ObjectType->equals(TemplateObjectType) was true (which is worst since TemplateObjectType->equals(ObjectType) was false.

But, with our integration tests it shows that this fix will break

I got confirmation from ondrej that my fix was correct and your implementation had some issues (phpstan/phpstan-src#5399 (comment))
After some investigations, it seems like this is because you rely a lot on Type::equals, for instance here:
https://github.com/rectorphp/rector-downgrade-php/blob/15578226e7d293f224a121dabaa11d8f6e7ab42a/rules/DowngradePhp74/Rector/ClassMethod/DowngradeCovariantReturnTypeRector.php#L239

This had the benefit BEFORE to return true when you compares a FullyQualifiedObjectType (

final class FullyQualifiedObjectType extends ObjectType
) which the ObjectType of the same class. But as soon as the ObjectType::equals will be fixed it will returns false.

I'm not fully sure how to change your implementation, some ideas...

  • Using describe method
  • Using toPhpDocNode
  • Using $child->isSuperTypeOf($parent)
  • Overriding equals method in your custom ObjectType class

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions