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

[Php70] Handle crash on IfToSpaceshipRector with enum case #3317

Merged
merged 9 commits into from
Jan 29, 2023

Conversation

samsonasik
Copy link
Member

@samsonasik samsonasik commented Jan 29, 2023

Given the following code:

enum Status {
    case Foo;
    case Bar;
}

final class Service {
    public function status(int $param): Status {
        /**
         * These pass:
         *
         * - if ($param)
         * - if (true)
         */
        if ($param === 1) {
            return Status::Foo;
        }

        return Status::Bar;
    }
}

It produce crash:

There was 1 error:

1) Rector\Tests\Php70\Rector\If_\IfToSpaceshipRector\IfToSpaceshipRectorTest::test with data set #2 ('/Users/samsonasik/www/rector-...hp.inc')
LogicException: This enum case does not have a value

phar:///Users/samsonasik/www/rector-src/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflection/ReflectionEnumCase.php:99
phar:///Users/samsonasik/www/rector-src/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflection/Adapter/ReflectionClassConstant.php:64
phar:///Users/samsonasik/www/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ClassConstantReflection.php:78
/Users/samsonasik/www/rector-src/src/PhpParser/Node/Value/ValueResolver.php:300
/Users/samsonasik/www/rector-src/src/PhpParser/Node/Value/ValueResolver.php:191

This PR try to fix it. Fixes rectorphp/rector#7737 Fixes rectorphp/rector#7736

@samsonasik
Copy link
Member Author

Fixed 🎉 /cc @mpesari

@samsonasik samsonasik force-pushed the skip-class-constant-enum branch 2 times, most recently from 7c706f6 to c93036f Compare January 29, 2023 08:05
@samsonasik samsonasik force-pushed the skip-class-constant-enum branch from 6e3839a to 2f4d20b Compare January 29, 2023 08:09
@samsonasik
Copy link
Member Author

this should also fix rectorphp/rector#7736

@samsonasik
Copy link
Member Author

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

@TomasVotruba TomasVotruba merged commit b98de3e into main Jan 29, 2023
@TomasVotruba TomasVotruba deleted the skip-class-constant-enum branch January 29, 2023 09:48
@TomasVotruba
Copy link
Member

Thank you 👍

@mpesari
Copy link

mpesari commented Jan 29, 2023

Thanks!

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