Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Jun 17, 2025

Comment on lines -22 to -44
-----
<?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;
}
}

?>
Copy link
Contributor Author

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

Copy link
Member

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

Copy link
Contributor Author

@staabm staabm Jun 17, 2025

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

Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

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 :)

Copy link
Member

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.

@samsonasik samsonasik merged commit 9663a58 into rectorphp:main Jun 17, 2025
45 checks passed
@samsonasik
Copy link
Member

Thank you @staabm

@staabm
Copy link
Contributor Author

staabm commented Jun 17, 2025

Thx

@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Skip ExplicitReturnNullRector on code which contains goto

2 participants