Skip to content

[Arguments] Fix ReplaceArgumentDefaultValueRector re-applying already-migrated imported class constant - #8475

Merged
TomasVotruba merged 1 commit into
mainfrom
worktree-fix-9898-replace-arg-default-idempotency
Sep 8, 2026
Merged

[Arguments] Fix ReplaceArgumentDefaultValueRector re-applying already-migrated imported class constant#8475
TomasVotruba merged 1 commit into
mainfrom
worktree-fix-9898-replace-arg-default-idempotency

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Sep 8, 2026

Copy link
Copy Markdown
Member

Fixes #9898

Problem

ReplaceArgumentDefaultValueRector had two related defects when a scalar valueBefore is migrated to a class constant valueAfter (e.g. 'lax' -> Cookie::SAMESITE_LAX):

  1. Re-applies on already-migrated code. After the first run the argument holds Cookie::SAMESITE_LAX, which resolves back to 'lax', so the rule matched it again and rewrote the constant to a fully qualified re-fetch on every run. The existing idempotency guard only covered self::/static::/parent:: constants (isSpecialClassName()), not imported/FQ class constants.

  2. Change not reported in applied rules. processReplaces() mutates the node in place and returns the same instance, but the caller checked $replacedNode !== $currentNode - always false - so valid migrations were applied to the AST without being attributed to the rule (diff shown, empty "Applied rules"). The sibling FunctionArgumentDefaultValueReplacerRector already uses the correct instanceof Node check.

Fix

  • Drop the isSpecialClassName() requirement from the already-at-target guard so imported class constants are skipped too.
  • Report a change whenever processReplaces() returns a non-null node, matching the sibling rule.

Test

Added skip_imported_class_const_already_replaced fixture asserting an argument already holding the target imported constant is left untouched.

…-migrated imported class constant and report change in applied rules
@TomasVotruba
TomasVotruba merged commit 63a2f16 into main Sep 8, 2026
43 checks passed
@TomasVotruba
TomasVotruba deleted the worktree-fix-9898-replace-arg-default-idempotency branch September 8, 2026 20:29
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.

ReplaceArgumentDefaultValueRector rule re-applied argument default

1 participant