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

[Experiment][TypeDeclaration] Allow change abstract class methods with body on ReturnType*Rector #5344

Merged
merged 8 commits into from
Dec 9, 2023

Conversation

samsonasik
Copy link
Member

@samsonasik samsonasik commented Dec 9, 2023

@TomasVotruba @staabm based on child return type sub type verification on previous PR:

This is experiment to allow abstract class methods with body to make return type as well on ClassMethodReturnTypeOverrideGuard service.

@samsonasik
Copy link
Member Author

For change in vendor + non-vendor location, it already verified on isReturnTypeChangeAllowed() method 👍

@samsonasik
Copy link
Member Author

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

@samsonasik
Copy link
Member Author

Ok, It seems it will cause a bug on union:

abstract class SomeAbstractWithUnion
{
    public function run()
    {
        if (rand(0, 1)) {
            return null;
        }

        return new \DateTime;
    }
}

final class NullableUnion extends SomeAbstractWithUnion
{
    public function run()
    {
        if (rand(0, 1)) {
            return null;
        }

        return new stdClass;
    }
}

it got:

 abstract class SomeAbstractWithUnion
 {
-    public function run()
+    public function run(): ?\DateTime
     {
         if (rand(0, 1)) {
             return null;
@@ @@
 
 final class NullableUnion extends SomeAbstractWithUnion
 {
-    public function run()
+    public function run(): ?\stdClass
     {
         if (rand(0, 1)) {
             return null;

on union type, it specifically on child verification tho, nothing todo with abstract, I will check in separate PR.

@samsonasik
Copy link
Member Author

Oh, it seems fine, it because I wrongly copy paste class name, I will add the fixture

@samsonasik
Copy link
Member Author

Added more fixtures :), Ready to review 👍

@samsonasik
Copy link
Member Author

samsonasik commented Dec 9, 2023

Ok, interface never have method with body, so I guess it can be rolled back for performance reason to skip it.

@samsonasik samsonasik changed the title [Experiment][TypeDeclaration] Allow change abstract/interface methods on ReturnType*Rector [Experiment][TypeDeclaration] Allow change abstractmethods on ReturnType*Rector Dec 9, 2023
@samsonasik samsonasik changed the title [Experiment][TypeDeclaration] Allow change abstractmethods on ReturnType*Rector [Experiment][TypeDeclaration] Allow change abstract class methods with body on ReturnType*Rector Dec 9, 2023
@@ -45,7 +45,7 @@ public function shouldSkipClassMethod(ClassMethod $classMethod, Scope $scope): b
return true;
}

if ($classReflection->isAbstract()) {
if ($classMethod->isAbstract()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

this is skip only on abstract method only, not abstract class 👍

@TomasVotruba
Copy link
Member

@samsonasik Feel free to go for merge, let's try this in real world 😉

@samsonasik
Copy link
Member Author

Ok, let's merge it ;)

@samsonasik samsonasik merged commit 99dbc0d into main Dec 9, 2023
41 checks passed
@samsonasik samsonasik deleted the type-allow-abstract branch December 9, 2023 17:13
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