Skip to content

Conversation

@samsonasik
Copy link
Member

@samsonasik samsonasik commented Sep 18, 2022

Given the following code:

class SkipNullableArrayOnNotEmpty
{
    public function getPrice()
    {
        $tierPrices = random_int(0, 1) ? [] : null;

        if (! empty($tierPrices)) {
            foreach ($tierPrices as $tierPrice) {
                if ($tierPrice >= 0) {
                    return $tierPrice;
                }
            }
        }

        return 0.0;
    }
}

It currently process remove empty check, which invalid as null cannot be looped:

https://getrector.org/demo/7bae65e2-e423-4713-939e-9350d2b10799

This PR fix it.

Fixes rectorphp/rector#7486

@samsonasik
Copy link
Member Author

Fixed 🎉 /cc @Wohlie

@samsonasik samsonasik force-pushed the skip-nullable-array-on-not-empty branch from f0b21cb to d0bd3d3 Compare September 18, 2022 03:30
@samsonasik
Copy link
Member Author

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

@TomasVotruba TomasVotruba merged commit 4923a14 into main Sep 18, 2022
@TomasVotruba TomasVotruba deleted the skip-nullable-array-on-not-empty branch September 18, 2022 11:33
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 RemoveUnusedNonEmptyArrayBeforeForeachRector

3 participants