Skip to content

[CodeQuality] Skip if else return on ExplicitReturnNullRector#5755

Merged
samsonasik merged 13 commits intomainfrom
skip-if-else
Mar 22, 2024
Merged

[CodeQuality] Skip if else return on ExplicitReturnNullRector#5755
samsonasik merged 13 commits intomainfrom
skip-if-else

Conversation

@samsonasik
Copy link
Copy Markdown
Member

@samsonasik
Copy link
Copy Markdown
Member Author

Fixed 🎉

@samsonasik
Copy link
Copy Markdown
Member Author

Try catch seems can always return inside If https://getrector.com/demo/25fe6ca5-f447-4ada-83c7-6a9c8d4bf692

We may need to use existing SilentVoidResolver for it.

@samsonasik
Copy link
Copy Markdown
Member Author

samsonasik commented Mar 22, 2024

I added another fixture in if else with try catch fixture 67e848e

@samsonasik
Copy link
Copy Markdown
Member Author

The logic for it should like in SilentVoidResolver

// has switch with always return
if ($stmt instanceof Switch_ && $this->isSwitchWithAlwaysReturn($stmt)) {
return false;
}
// is part of try/catch
if ($stmt instanceof TryCatch && $this->isTryCatchAlwaysReturn($stmt)) {
return false;
}
if ($stmt instanceof Throw_) {
return false;
}

the solution is either make that detection there, with if else check addition, and utilize ReturnTypeInferer to verify final type has Void type or check here more.

I will look more...

@samsonasik samsonasik self-assigned this Mar 22, 2024
@samsonasik
Copy link
Copy Markdown
Member Author

implemented 🎉 , I moved the functionality to SilentVoidResolver::hasSilentVoid() so it centralized for future improvement 👍

@samsonasik
Copy link
Copy Markdown
Member Author

All checks have passed 🎉 @TomasVotruba I am merging it ;)

@samsonasik samsonasik merged commit 32bf5c7 into main Mar 22, 2024
@samsonasik samsonasik deleted the skip-if-else branch March 22, 2024 16:51
@TomasVotruba
Copy link
Copy Markdown
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.

3 participants