Skip to content

Make AddProphecyTraitRector idempotent - #806

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-prophecy-idempotent
Oct 18, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
tv-prophecy-idempotent

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

AddProphecyTraitRector relied only on the class reflection to detect an already-present ProphecyTrait. When the rule runs more than once over the same class, the reflection does not yet see the trait added on the previous pass, so the rule keeps re-adding it.

Now the rule checks the existing TraitUse nodes on the class AST first, before the reflection-based check. This is immune to stale reflection and keeps the rule idempotent.

Harmless today, but the upcoming rector-src node-traverser simplification drops the created-by-rule reprocessing guard, so each rule must settle on its own.

Test, ECS and PHPStan pass.

Check existing trait uses structurally before the reflection-based
check, so the rule is not fooled by a class reflection that does not
yet see the ProphecyTrait added on a previous pass and keeps re-adding it.
@TomasVotruba
TomasVotruba merged commit 5b6b793 into main Oct 18, 2026
8 checks passed
@TomasVotruba
TomasVotruba deleted the tv-prophecy-idempotent branch October 18, 2026 13:24
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