Skip to content

[Php73] Skip prev() call on items after key called on ArrayKeyFirstLastRector#3293

Merged
TomasVotruba merged 3 commits intomainfrom
skip-prev-call
Jan 17, 2023
Merged

[Php73] Skip prev() call on items after key called on ArrayKeyFirstLastRector#3293
TomasVotruba merged 3 commits intomainfrom
skip-prev-call

Conversation

@samsonasik
Copy link
Copy Markdown
Member

Given the following code should be skipped:

        $items = [1, 2, 3];

        end($items);
        $key = key($items);

        while ($key !== null) {
            $isFound = rand(0, 1) ? true : false;

            if (! $isFound) {
                prev($items);
                $key = key($items);

                continue;
            }

            return current($items);
        }

as the end() is used to make the prev() working to point to previous key in the loop.

@samsonasik
Copy link
Copy Markdown
Member Author

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

@TomasVotruba TomasVotruba merged commit cec3a11 into main Jan 17, 2023
@TomasVotruba TomasVotruba deleted the skip-prev-call branch January 17, 2023 15:03
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.

2 participants