Skip to content

Conversation

@Mika-
Copy link
Contributor

@Mika- Mika- commented Jun 9, 2025

Prevents adding empty return when stringable always throws. Not sure if this is the right way to fix this.

https://getrector.com/demo/c4c2d42d-16f0-454d-af48-da9f06f84bf6

@samsonasik
Copy link
Member

You can use TerminatedNodeAnalyzer for that, see usage exanple on

if ($this->terminatedNodeAnalyzer->isAlwaysTerminated($stmtsAware, $previousStmt, $stmt)) {

On your use case, stmtsaware is class method, previous stmt is the Expression of Throw, and stmt is the return stmt.

Actually, if you combine with deadCode set, this already skipped as removed already, see

https://getrector.com/demo/e87c6d53-312b-4044-a46f-0007c65b06dc

@Mika- Mika- force-pushed the empty-stringable branch from 0b32383 to 958de43 Compare June 9, 2025 17:55
@Mika-
Copy link
Contributor Author

Mika- commented Jun 9, 2025

TerminatedNodeAnalyzer made it look much cleaner

@TomasVotruba
Copy link
Member

Thank you @Mika- 👍

@TomasVotruba TomasVotruba merged commit a5395fc into rectorphp:main Jun 9, 2025
45 checks passed
private const ALLOWED_CONTINUE_CURRENT_STMTS = [InlineHTML::class, Nop::class];

public function isAlwaysTerminated(StmtsAwareInterface $stmtsAware, Stmt $node, Stmt $currentStmt): bool
public function isAlwaysTerminated(StmtsAwareInterface|ClassMethod $stmtsAware, Stmt $node, Stmt $currentStmt): bool
Copy link
Member

Choose a reason for hiding this comment

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

This change is not needed, ClassMethod is already instanceof StmtsAwareInterface

Copy link
Member

Choose a reason for hiding this comment

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

@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 28, 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.

3 participants