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

[Php72] Handle crash on trailing comma last on WhileEachToForeachRector #3186

Merged
merged 3 commits into from
Dec 11, 2022

Conversation

samsonasik
Copy link
Member

@samsonasik samsonasik commented Dec 11, 2022

Given the following code:

final class TrailingCommaLast
{
    public function run()
    {
        while(list($code_name,) = each($poster_xd))
        {
            $poster_xd[$code_name] = preg_replace($orig_word, $replacement_word, $poster_xd[$code_name]);
        }
    }
}

It cause crash:

There was 1 error:

1) Rector\Tests\Php72\Rector\While_\WhileEachToForeachRector\WhileEachToForeachRectorTest::test with data set #3 ('/Users/samsonasik/www/rector-...hp.inc')
TypeError: PhpParser\Node\Stmt\Foreach_::__construct(): Argument #2 ($valueVar) must be of type PhpParser\Node\Expr, null given, called in /Users/samsonasik/www/rector-src/rules/Php72/Rector/While_/WhileEachToForeachRector.php on line 131

Ref https://getrector.org/demo/ec8b7f3a-918f-4bfe-bf70-28fa2a992916
Fixes rectorphp/rector#7654

The transformation should be

https://3v4l.org/mTeIL#v7.1.31 --> https://3v4l.org/UJH9S

@samsonasik
Copy link
Member Author

Fixed 🎉 /cc @scottybcoder

@samsonasik
Copy link
Member Author

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

@TomasVotruba
Copy link
Member

Thank you 👏

@TomasVotruba TomasVotruba merged commit 802d98e into main Dec 11, 2022
@TomasVotruba TomasVotruba deleted the handle-crash-trailing-comma-last branch December 11, 2022 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants