Skip to content

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 draft August 23, 2022 20:17
@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

Development

Successfully merging this pull request may close these issues.

Incorrect behavior of RemoveAlwaysElseRector

5 participants