Skip to content

Make RemoveNullFromNullableCollectionTypeRector idempotent - #534

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

TomasVotruba merged 1 commit into
mainfrom
tv-doctrine-idempotent

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

When the native property type is nullable (?Collection), the rule unwraps it and leaves the docblock as-is. The resulting property - non-nullable native Collection with a @var ...|null docblock - is structurally identical to the docblock-cleaning branch's input, so running the rule again would rewrite that docblock (dropping |null).

The two cases are told apart by the original node: when the original native type was nullable, the unwrap branch owns the property and the docblock branch is skipped. This keeps the rule idempotent without changing any fixture, and leaves the three genuine docblock-cleaning fixtures untouched.

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.

Rule test, ECS and PHPStan pass.

When the native property type is nullable, unwrapping it leaves a
property matching the docblock-cleaning branch, so a later pass would
rewrite the still-nullable docblock. Skip that branch when the original
native type was nullable, detected via the original node.
@TomasVotruba
TomasVotruba force-pushed the tv-doctrine-idempotent branch from be5898c to 316868b Compare October 18, 2026 14:50
@TomasVotruba
TomasVotruba merged commit 47eda72 into main Oct 18, 2026
8 checks passed
@TomasVotruba
TomasVotruba deleted the tv-doctrine-idempotent branch October 18, 2026 19:57
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