Skip to content

[CodeQuality] Add ExplicitNullableObjectInstanceRector, deprecate 4 nullable-object instanceof rules - #8636

Merged
TomasVotruba merged 3 commits into
mainfrom
tv-explicit-nullable-object-instance
Oct 11, 2026
Merged

TomasVotruba merged 3 commits into
mainfrom
tv-explicit-nullable-object-instance

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Merges four rules that all rewrite an implicit nullable-object check into an explicit instanceof, into a single ExplicitNullableObjectInstanceRector. Each old rule only differed in the input idiom; the output and the underlying factory are the same.

Merged (now deprecated, kept as throwing stubs for BC):

  • ObjectExplicitBoolCompareRector - !$item / $item
  • FlipTypeControlToUseExclusiveTypeRector - $item === null / !== null
  • EmptyOnNullableObjectToInstanceOfRector - empty($item) / !empty($item)
  • WhileNullableToInstanceofRector - while ($item !== null) / while ($item)

All four produce $item instanceof X (negated as needed) via the shared NullableObjectToInstanceofFactory. The new rule subscribes to the union of their node types and dispatches by node, keeping each original detection and type-resolution path intact.

BinaryOpNullableToInstanceofRector (&& / ||) stays separate as requested.

The rule is registered in CodeQualityLevel; the two old entries there and the two in TypeDeclarationLevel are removed. Two tests/Issues configs that pinned the old rules by class-string are repointed to the new rule.

Fixtures cover every idiom (truthiness, null compare, empty, while/do-while) plus a nullable-scalar skip. Full suite green locally.

…able-object instanceof rules, deprecate them
@TomasVotruba

Copy link
Copy Markdown
Member Author

These 4 rules do basically the same operation, nullable object + weak condition around it →instanceof check 👍
You want them all or none. This will speed up the process a bit and streamline its usage.

@TomasVotruba
TomasVotruba merged commit 9ac158f into main Oct 11, 2026
49 checks passed
@TomasVotruba
TomasVotruba deleted the tv-explicit-nullable-object-instance branch October 11, 2026 20:33
@parijke

parijke commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

@TomasVotruba I already found this in the public docs, but it isn't released yet?

@TomasVotruba

Copy link
Copy Markdown
Member Author

That's because website deploys regularly with latest version to allow demo testing 👍

@parijke

parijke commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

That's because website deploys regularly with latest version to allow demo testing 👍

Good to know!

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.

2 participants