Skip to content

Ignore false-positive cheaper-guard order in DowngradeSubstrFalsyRector - #391

Merged
TomasVotruba merged 1 commit into
mainfrom
cheaper-guards-first-ignore
Aug 29, 2026
Merged

Ignore false-positive cheaper-guard order in DowngradeSubstrFalsyRector#391
TomasVotruba merged 1 commit into
mainfrom
cheaper-guards-first-ignore

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

symplify/phpstan-rules 14.13.0 adds RectorCheaperGuardsFirstRule, which flags a cheap guard placed after an expensive analysis call.

In DowngradeSubstrFalsyRector the isName($node, 'substr') guard is flagged, but it cannot be hoisted: the preceding CallLike block marks IS_FALSY_UNCASTABLE on the arguments of non-substr call nodes, and that side effect is what lets nested substr() in falsy-tolerant parameter positions be skipped later. Moving the guard up would make non-substr nodes bail before the marking runs, wrongly rewriting those nested calls (covered by skip_as_falsy_arg and skip_new_arg_falsy fixtures).

Adds a narrow inline @phpstan-ignore with the reason. Genuine false positive for this method.

The isName() guard cannot move above the CallLike block, which marks
IS_FALSY_UNCASTABLE on arguments of non-substr call nodes; hoisting would skip
that side effect and wrongly rewrite nested substr() in falsy-tolerant params.

Claude-Session: https://claude.ai/code/session_01Na4eYvNqa2pdhZrBXbegrv
@TomasVotruba
TomasVotruba merged commit 4010c8b into main Aug 29, 2026
9 checks passed
@TomasVotruba
TomasVotruba deleted the cheaper-guards-first-ignore branch August 29, 2026 17:32
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