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

[EarlyReturn] Handle crash on assign in if else before on RemoveAlwaysElseRector #2822

Merged
merged 9 commits into from
Aug 23, 2022

Conversation

samsonasik
Copy link
Member

@samsonasik samsonasik commented Aug 23, 2022

Closes #2821 Fixes rectorphp/rector#7412

Given the following code:

function assignInIfElseBefore($can_order_products, $offset, $limit)
{
    if (!empty($can_order_products)) {
        if (!empty($limit)) {
            if (!empty($offset)) {
                $can_order_products = array_slice($can_order_products, $offset, $limit);
            } else {
                $can_order_products = array_slice($can_order_products, 0, $limit);
            }

            if (!empty($can_order_products)) {
                return $can_order_products;
            } else {
                return false;
            }
        } else {
            return $can_order_products;
        }
    }

    return false;
}

It currently produce error:

There was 1 failure:

1) Rector\Tests\EarlyReturn\Rector\If_\RemoveAlwaysElseRector\RemoveAlwaysElseRectorTest::test with data set #4 (Symplify\SmartFileSystem\SmartFileInfo Object (...))
assert($itemStartPos >= 0 && $itemEndPos >= 0 && $itemStartPos >= $pos) in /Users/samsonasik/www/rector-src/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinterAbstract.php:759

@samsonasik samsonasik marked this pull request as ready for review August 23, 2022 20:31
@samsonasik
Copy link
Member Author

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

@TomasVotruba TomasVotruba merged commit 54feb0d into main Aug 23, 2022
@TomasVotruba TomasVotruba deleted the close-2821 branch August 23, 2022 20:51
@TomasVotruba
Copy link
Member

Thank you 👍

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