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

[TypeDeclaration] Skip return after return closure on AddVoidReturnTypeWhereNoReturnRector #4930

Merged
merged 2 commits into from Sep 7, 2023

Conversation

samsonasik
Copy link
Member

@staabm here the following code should be skipped as returns something:

final class SkipReturnAfterClosureReturn
{
    private function run($someObject)
    {
        $someData = $someObject->run('foo', function (): array {
            return [];
        }, strtotime('+6 hours'));

        return $someData[$this->get()];
    }
}

Ref https://getrector.com/demo/1f06cf14-382e-4161-ba39-d2061164ebab

Comment on lines +44 to +51
$returns = $this->betterNodeFinder->findInstancesOfInFunctionLikeScoped($functionLike, Return_::class);
foreach ($returns as $return) {
if ($return->expr instanceof Expr) {
return false;
}
}

return true;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staabm fixed with revert the logic from your PR:

as no returns at all need to be checked to return true.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staabm the BetterNodeFinder::findFirstInFunctionLikeScoped() seems needs refactor to ensure find next on scoped search, I created new PR for it to keep using findFirstInFunctionLikeScoped()

@samsonasik samsonasik enabled auto-merge (squash) September 7, 2023 02:07
@samsonasik samsonasik merged commit 54799fc into main Sep 7, 2023
39 of 40 checks passed
@samsonasik samsonasik deleted the skip-return branch September 7, 2023 02:07
@staabm
Copy link
Contributor

staabm commented Sep 7, 2023

Good catch

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