Skip to content

feat: add IntersectionType support to PropertyCreateMockToCreateStubRector#661

Open
asumikam wants to merge 1 commit intorectorphp:mainfrom
asumikam:feat/support-intersection-type
Open

feat: add IntersectionType support to PropertyCreateMockToCreateStubRector#661
asumikam wants to merge 1 commit intorectorphp:mainfrom
asumikam:feat/support-intersection-type

Conversation

@asumikam
Copy link

Summary

This PR enables PropertyCreateMockToCreateStubRector to correctly handle IntersectionType (e.g., MockObject&\stdClass).

Motivation

Thank you for the continuous development of Rector.
While using this Rector in my own project for migration, I noticed that property types were not being handled correctly when they contained intersection types.

I have verified that this change allows for a clean migration in my project's codebase.

Changes

Previously, the rector unconditionally replaced the property type with FullyQualified(PHPUnitClassName::STUB), which broke intersection types. This PR introduces an updatePropertyType() method to handle two specific cases:

  • IntersectionType: Iterates through inner types, replacing only MockObject with Stub while preserving the other members (e.g., MockObject&\stdClassStub&\stdClass).
  • Non-intersection: Replaces the entire type with Stub (original behavior).

Please let me know if there are any edge cases I might have missed or if further adjustments are needed.
Thank you for your time and review!

@asumikam asumikam force-pushed the feat/support-intersection-type branch from 1404d2c to 255f02e Compare February 24, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant