Skip to content

[CodeQuality] Extract NullableObjectToInstanceofFactory shared by nullable-object instanceof rules - #8633

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-nullable-instanceof-factory
Oct 11, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
tv-nullable-instanceof-factory

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Four rules independently built the same $expr instanceof X node from a nullable ObjectType, each with its own private helper:

  • ObjectExplicitBoolCompareRector - resolveNullable()
  • FlipTypeControlToUseExclusiveTypeRector - processConvertToExclusiveType()
  • BinaryOpNullableToInstanceofRector - createExprInstanceof()
  • WhileNullableToInstanceofRector - createInstanceof()

This extracts the shared node construction into NullableObjectToInstanceofFactory::create(Expr, ObjectType, bool $isNegated) and migrates all four rules to it. The factory keeps the ShortenedObjectType/AliasedObjectType FQCN handling from FlipTypeControl - the other callers never hit those branches, so behavior is unchanged.

Only node construction is shared. Each rule keeps its own type-resolution path (nodeTypeResolver, nullableTypeAnalyzer, native scope type), since those differ in depth and source and are sensitive to resolution order.

EmptyOnNullableObjectToInstanceOfRector is intentionally left out - it maps the type through StaticTypeMapper to a Name rather than building a FullyQualified from the class name.

Rules stay separate on purpose: they match different input idioms (!$item, $item === null, &&/||, while) and converge on the same output.

No behavior change. Fixtures untouched, all pass.

@TomasVotruba
TomasVotruba merged commit 6ba042e into main Oct 11, 2026
49 checks passed
@TomasVotruba
TomasVotruba deleted the tv-nullable-instanceof-factory branch October 11, 2026 17:41
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