Skip to content

[Php71/Php73] Skip call expression in IsCountableRector and IsIterableRector - #9038

Merged
TomasVotruba merged 1 commit into
mainfrom
is-countable-skip-call-expr
Nov 23, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
is-countable-skip-call-expr

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

IsCountableRector and IsIterableRector merged the two checks into one even when the checked expression is a call:

// before
is_array($foo->execute()) || $foo->execute() instanceof \Countable;
is_array($foo->execute()) || $foo->execute() instanceof \Traversable;

// after
is_countable($foo->execute());
is_iterable($foo->execute());

The original calls execute() twice, the new code once. If the two calls return different values (e.g. [] first, then a Countable) or have side effects, the result and the call count change.

The fix is in the shared IsArrayAndDualCheckToAble helper, so both rules apply only when the checked expression has no side effects - a variable, property fetch, static property fetch, or array dim fetch of those. The on_method_call fixture of IsCountableRector is now skip_method_call, IsIterableRector gets the same skip fixture, and a new fixture covers property and array dim fetches.

@TomasVotruba
TomasVotruba force-pushed the is-countable-skip-call-expr branch from 9eba280 to 2e8f3b8 Compare November 23, 2026 21:53
@TomasVotruba TomasVotruba changed the title [Php73] Skip call expression in IsCountableRector [Php71/Php73] Skip call expression in IsCountableRector and IsIterableRector Nov 23, 2026
@TomasVotruba
TomasVotruba merged commit 567a18a into main Nov 23, 2026
51 checks passed
@TomasVotruba
TomasVotruba deleted the is-countable-skip-call-expr branch November 23, 2026 22: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