Skip to content

[CodeQuality] Add AddStubIntersectionVarToStubPropertyRector#700

Merged
TomasVotruba merged 6 commits into
mainfrom
add-stub-intersection-var-rule
Jun 29, 2026
Merged

[CodeQuality] Add AddStubIntersectionVarToStubPropertyRector#700
TomasVotruba merged 6 commits into
mainfrom
add-stub-intersection-var-rule

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Jun 29, 2026

Copy link
Copy Markdown
Member

Adds AddStubIntersectionVarToStubPropertyRector to the mock-to-stub set.

When a test property is typed as a bare native Stub and setUp() assigns it via createStub(), add a @var Stub&MockedClass intersection docblock:

private \PHPUnit\Framework\MockObject\Stub $pathsHelper;

protected function setUp(): void
{
    $this->pathsHelper = $this->createStub(PathsHelper::class);
}

/**
 * @var \PHPUnit\Framework\MockObject\Stub&\PathsHelper
 */
private \PHPUnit\Framework\MockObject\Stub $pathsHelper;

Stub analog of AddIntersectionVarToMockObjectPropertyRector. MockObjectPropertyDetector generalized (parametric on class name + create-method) and shared by both rules.

Skips: existing intersection @var, non-test classes, MockObject-typed properties.

Add @var Stub&MockedClass intersection docblock to a bare native Stub property whose setUp() assigns createStub(). Generalize MockObjectPropertyDetector to be parametric on class name + create method, shared by both mock and stub rules.
@TomasVotruba TomasVotruba marked this pull request as ready for review June 29, 2026 21:48
… intersection @var rules

Generalize MockObjectPropertyDetector to collect both $this->create*() (MethodCall) and self::create*() (StaticCall). Widen both rules' class resolvers accordingly. Add static-call fixtures.
…sectionVarToStubPropertyRector

Iterate all native-Stub properties: derive the stubbed class from a setUp() createStub() arg when present, else from a bare single-class @var docblock. Absorbs and removes BareVarToStubIntersectionRector. Stub-first intersection ordering.
@TomasVotruba TomasVotruba merged commit 3f62270 into main Jun 29, 2026
8 checks passed
@TomasVotruba TomasVotruba deleted the add-stub-intersection-var-rule branch June 29, 2026 22:17
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