Skip to content

[CodeQuality] Flip void-method with(callback) to willReturnCallback, rename rule#724

Merged
TomasVotruba merged 4 commits into
mainfrom
flip-void-with-callback-to-willreturncallback
Jul 13, 2026
Merged

[CodeQuality] Flip void-method with(callback) to willReturnCallback, rename rule#724
TomasVotruba merged 4 commits into
mainfrom
flip-void-with-callback-to-willreturncallback

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Jul 13, 2026

Copy link
Copy Markdown
Member

Renames RemoveReturnFromVoidMethodMockCallbackRectorVoidMethodWithCallbackToWillReturnCallbackRector and refocuses it.

The old name no longer described the behavior: the rule now flips a ->with($this->callback(...)) matcher on a void mocked method into a ->willReturnCallback() call, dropping the now-pointless value return and typing the closure as void. Plain ->willReturnCallback() closures are left untouched.

Before / after

 $this->createMock(SomeClass::class)
     ->method('run') // run(): void
-    ->with($this->callback(function ($arg) {
+    ->willReturnCallback(function ($arg): void {
         echo $arg;
-
-        return true;
-    }));
+    });

Notes

  • Only applies when the mocked method returns void (reflection-checked).
  • Safety kept: bails on nested closures and on non-pure returned values; return throw unwraps to a bare throw.
  • Plain ->willReturnCallback(...) closures are left untouched.

@TomasVotruba TomasVotruba merged commit 7e13bfb into main Jul 13, 2026
8 checks passed
@TomasVotruba TomasVotruba deleted the flip-void-with-callback-to-willreturncallback branch July 13, 2026 10:31
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