Skip to content

[CodeQuality] Move AssertClassToThisAssertRector hook from Class_ to ClassMethod#728

Merged
TomasVotruba merged 2 commits into
mainfrom
move-assert-class-to-this-assert-to-class-method
Jul 14, 2026
Merged

[CodeQuality] Move AssertClassToThisAssertRector hook from Class_ to ClassMethod#728
TomasVotruba merged 2 commits into
mainfrom
move-assert-class-to-this-assert-to-class-method

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

The rule only ever rewrote Assert::assert*() calls inside class methods, so hooking on ClassMethod is more precise than hooking on the whole Class_ and re-traversing it.

Behavior is unchanged:

 final class SomeTest extends TestCase
 {
     public function testMe()
     {
-        Assert::assertSame(1, 1);
+        $this->assertSame(1, 1);
     }
 }

Static methods are now skipped with an early return instead of a DONT_TRAVERSE_CURRENT_AND_CHILDREN check inside the traversal callback:

public function refactor(Node $node): ?Node
{
    if ($node->isStatic()) {
        return null;
    }
    // ...
}

Static closures and arrow functions are still skipped during traversal.

The rule and its tests move from Rector/Class_/ to Rector/ClassMethod/ to match the hooked node type.

…ClassMethod

The rule only ever rewrote Assert::assert*() calls inside class methods, so hooking on ClassMethod is more precise and avoids re-traversing the whole class.

Static methods are now skipped with an early return instead of a DONT_TRAVERSE_CURRENT_AND_CHILDREN check inside the traversal callback; static closures and arrow functions are still skipped during traversal.
@TomasVotruba TomasVotruba merged commit f450d2c into main Jul 14, 2026
8 checks passed
@TomasVotruba TomasVotruba deleted the move-assert-class-to-this-assert-to-class-method branch July 14, 2026 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant