Skip to content

[Rector] Skip refactor() delegating REMOVE_NODE to helper methods - #279

Merged
TomasVotruba merged 1 commit into
mainfrom
fix-delegated-refactor-remove-node
Aug 24, 2026
Merged

[Rector] Skip refactor() delegating REMOVE_NODE to helper methods#279
TomasVotruba merged 1 commit into
mainfrom
fix-delegated-refactor-remove-node

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

NoIntegerRefactorReturnRule only scanned the refactor() body for NodeVisitor/NodeTraverser constants. When refactor() delegates the int return to private helper methods, its own body contains zero constants — the old $constantNames === [] branch then fell through and reported an error, even when every helper returned the allowed REMOVE_NODE.

Real-world false positive: Rector's own RemovePhpVersionIdCheckRector, whose refactor() delegates entirely to refactorConstFetch() / refactorSmaller() / etc., all returning NodeVisitor::REMOVE_NODE.

Fix

Scan the whole class for used traverser constants (refactor helpers included), and only report when an undesired constant (anything other than REMOVE_NODE) is actually present.

Before / after

// bad — helper uses DONT_TRAVERSE_CHILDREN, still flagged
public function refactor(Node $node): null|int
{
    return $this->doRefactor($node);
}
private function doRefactor(Node $node): null|int
{
    return NodeVisitor::DONT_TRAVERSE_CHILDREN;
}
// good — helper only returns REMOVE_NODE, now correctly skipped
public function refactor(Node $node): null|int
{
    return $this->doRefactor($node);
}
private function doRefactor(Node $node): null|int
{
    return NodeVisitor::REMOVE_NODE;
}

@TomasVotruba
TomasVotruba merged commit 6d51af2 into main Aug 24, 2026
8 checks passed
@TomasVotruba
TomasVotruba deleted the fix-delegated-refactor-remove-node branch August 24, 2026 23:32
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.

1 participant