Skip to content

[CodeQuality] Keep earlier change when a later call changes nothing in TypeWillReturnCallableArrowFunctionRector - #855

Merged
TomasVotruba merged 1 commit into
mainfrom
type-will-return-callable-accumulate-changes
Dec 1, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
type-will-return-callable-accumulate-changes

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

$hasChanged was reset to false for every matched mock call, so when a later call in the class needed no change, the rule returned null and the type already added to an earlier closure was dropped:

->method('someMethod')->willReturnCallback(fn ($name) => $value);      // should get (string $name): int
->method('nativeObject')->willReturnCallback(fn (object $object): \stdClass => $value);  // already typed

The reset is removed so changes accumulate across calls. Added a fixture with two calls where only the first changes.

Note: #846 touches this rule too (skips the with() callback); the changes are independent.

@TomasVotruba
TomasVotruba merged commit 259a4b1 into main Dec 1, 2026
15 checks passed
@TomasVotruba
TomasVotruba deleted the type-will-return-callable-accumulate-changes branch December 1, 2026 22:01
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