diff --git a/rules-tests/PHPUnit120/Rector/Property/BareVarToStubIntersectionRector/Fixture/bare_var.php.inc b/rules-tests/PHPUnit120/Rector/Property/BareVarToStubIntersectionRector/Fixture/bare_var.php.inc index d29474897..c1b96e07f 100644 --- a/rules-tests/PHPUnit120/Rector/Property/BareVarToStubIntersectionRector/Fixture/bare_var.php.inc +++ b/rules-tests/PHPUnit120/Rector/Property/BareVarToStubIntersectionRector/Fixture/bare_var.php.inc @@ -23,7 +23,7 @@ use PHPUnit\Framework\TestCase; final class BareVarTest extends TestCase { /** - * @var FormBuilderInterface&Stub + * @var FormBuilderInterface&\PHPUnit\Framework\MockObject\Stub */ private \PHPUnit\Framework\MockObject\Stub $formBuilder; } diff --git a/rules-tests/PHPUnit120/Rector/Property/MockObjectVarToStubRector/Fixture/intersection_type.php.inc b/rules-tests/PHPUnit120/Rector/Property/MockObjectVarToStubRector/Fixture/intersection_type.php.inc index 975a0e619..37e4d889c 100644 --- a/rules-tests/PHPUnit120/Rector/Property/MockObjectVarToStubRector/Fixture/intersection_type.php.inc +++ b/rules-tests/PHPUnit120/Rector/Property/MockObjectVarToStubRector/Fixture/intersection_type.php.inc @@ -25,7 +25,7 @@ use PHPUnit\Framework\TestCase; final class IntersectionTypeTest extends TestCase { /** - * @var FieldModel&Stub + * @var FieldModel&\PHPUnit\Framework\MockObject\Stub */ private \PHPUnit\Framework\MockObject\Stub $leadFieldModel; } diff --git a/rules-tests/PHPUnit120/Rector/Property/MockObjectVarToStubRector/Fixture/union_type.php.inc b/rules-tests/PHPUnit120/Rector/Property/MockObjectVarToStubRector/Fixture/union_type.php.inc index 7297f0b75..e3365b836 100644 --- a/rules-tests/PHPUnit120/Rector/Property/MockObjectVarToStubRector/Fixture/union_type.php.inc +++ b/rules-tests/PHPUnit120/Rector/Property/MockObjectVarToStubRector/Fixture/union_type.php.inc @@ -25,7 +25,7 @@ use PHPUnit\Framework\TestCase; final class UnionTypeTest extends TestCase { /** - * @var FieldModel|Stub + * @var FieldModel|\PHPUnit\Framework\MockObject\Stub */ private \PHPUnit\Framework\MockObject\Stub $leadFieldModel; } diff --git a/rules/PHPUnit120/Rector/Property/BareVarToStubIntersectionRector.php b/rules/PHPUnit120/Rector/Property/BareVarToStubIntersectionRector.php index 614715ecb..081df04fa 100644 --- a/rules/PHPUnit120/Rector/Property/BareVarToStubIntersectionRector.php +++ b/rules/PHPUnit120/Rector/Property/BareVarToStubIntersectionRector.php @@ -87,7 +87,7 @@ public function getRuleDefinition(): RuleDefinition , <<<'CODE_SAMPLE' /** - * @var FormBuilderInterface&Stub + * @var FormBuilderInterface&\PHPUnit\Framework\MockObject\Stub */ private \PHPUnit\Framework\MockObject\Stub $formBuilder; CODE_SAMPLE @@ -128,7 +128,10 @@ private function addStubIntersection(VarTagValueNode $varTagValueNode): bool return false; } - $varTagValueNode->type = new BracketsAwareIntersectionTypeNode([$typeNode, new IdentifierTypeNode('Stub')]); + $varTagValueNode->type = new BracketsAwareIntersectionTypeNode([ + $typeNode, + new IdentifierTypeNode('\\' . PHPUnitClassName::STUB), + ]); return true; } diff --git a/rules/PHPUnit120/Rector/Property/MockObjectVarToStubRector.php b/rules/PHPUnit120/Rector/Property/MockObjectVarToStubRector.php index a9011365f..47436448a 100644 --- a/rules/PHPUnit120/Rector/Property/MockObjectVarToStubRector.php +++ b/rules/PHPUnit120/Rector/Property/MockObjectVarToStubRector.php @@ -88,7 +88,7 @@ public function getRuleDefinition(): RuleDefinition , <<<'CODE_SAMPLE' /** - * @var FieldModel|Stub + * @var FieldModel|\PHPUnit\Framework\MockObject\Stub */ private \PHPUnit\Framework\MockObject\Stub $leadFieldModel; CODE_SAMPLE @@ -120,7 +120,7 @@ private function replaceMockObjectWithStub(VarTagValueNode $varTagValueNode): bo $hasChanged = false; foreach ($typeNode->types as $key => $innerType) { if ($innerType instanceof IdentifierTypeNode && $this->isMockObjectIdentifier($innerType)) { - $typeNode->types[$key] = new IdentifierTypeNode($this->resolveStubName($innerType->name)); + $typeNode->types[$key] = new IdentifierTypeNode('\\' . PHPUnitClassName::STUB); $hasChanged = true; } } @@ -129,7 +129,7 @@ private function replaceMockObjectWithStub(VarTagValueNode $varTagValueNode): bo } if ($typeNode instanceof IdentifierTypeNode && $this->isMockObjectIdentifier($typeNode)) { - $varTagValueNode->type = new IdentifierTypeNode($this->resolveStubName($typeNode->name)); + $varTagValueNode->type = new IdentifierTypeNode('\\' . PHPUnitClassName::STUB); return true; } @@ -145,13 +145,4 @@ private function isMockObjectIdentifier(IdentifierTypeNode $identifierTypeNode): return $shortName === 'MockObject'; } - - private function resolveStubName(string $name): string - { - $lastBackslashPosition = strrpos($name, '\\'); - - return $lastBackslashPosition === false - ? 'Stub' - : substr($name, 0, $lastBackslashPosition + 1) . 'Stub'; - } }