-
-
Notifications
You must be signed in to change notification settings - Fork 424
ExplicitReturnNullRector: skip on goto #6988
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
Conversation
rules/CodeQuality/Rector/ClassMethod/ExplicitReturnNullRector.php
Outdated
Show resolved
Hide resolved
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Tests\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector\Fixture; | ||
|
|
||
| final class DoWhileMaybeReturned4 | ||
| { | ||
| public function run(int $i) | ||
| { | ||
| do { | ||
| if (rand(0, 1)) { | ||
| goto execute; | ||
| } | ||
|
|
||
| return 2; | ||
| } while (++$i < 1); | ||
| execute: | ||
| echo 'test'; | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| ?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hopefully its fine to skip this case, as I think it is not very useful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add return null after echo 'test' is valid here, so probably verify if it has label.
It also probably more verifiable via TerminatedNodeAnalyzer service
| public function isAlwaysTerminated(StmtsAwareInterface $stmtsAware, Stmt $node, Stmt $currentStmt): bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it is technically allowed, but I think its not valuable to complicate the rector for goto cases.
I would just leave code with goto alone as it might have suprising logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will check if that can be covered via TerminatedNodeAnalyzer service :), otherwise, I can just merge it later if that too complex to cover
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created PR with utilize TerminatedNodeAnalyzer at:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some try, it indeed to complicated to tweak, I can merge this for now :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@staabm I created properly new PR to handle this:
which check on SilentVoidResolver instead.
|
Thank you @staabm |
|
Thx |
|
This pull request has been automatically locked because it has been closed for 150 days. Please open a new PR if you want to continue the work. |
closes rectorphp/rector#9224