Conversation
The search for the return ran in local mode, which stops at the first statement terminator, so a return after any other statement was missed and the rest of the callback was flagged. It now accepts a return that belongs to the if itself. A return inside a nested condition or closure no longer counts, because it does not stop the other queries from reaching the code below. The old search accepted those when they came first.
PHPStan is configured to analyse as PHP 7.1, where array_key_last() does not exist. Use the array_keys() and array_pop() pattern the sniff already uses elsewhere.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A
pre_get_postscallback that returns early for anything other than the main query was still flagged if thereturnwas not the first statement in theif, for example when it logged something first.The sniff now accepts a
returnanywhere in theif, as long as it belongs to theifitself.That last part changes behaviour in one direction worth knowing about. A
returninside a nested condition or a nested closure no longer counts as an early exit, so the code below it is flagged. The old search accepted those when they came first in theif, but they do not stop other queries from reaching the code below.This touches the same lines as #901, so whichever merges second will need a small conflict fix.
Fixes #902