diff --git a/rules-tests/DeadCode/Rector/ClassLike/RemoveTypedPropertyNonMockDocblockRector/Fixture/fixture.php.inc b/rules-tests/DeadCode/Rector/ClassLike/RemoveTypedPropertyNonMockDocblockRector/Fixture/fixture.php.inc deleted file mode 100644 index c483de715a1..00000000000 --- a/rules-tests/DeadCode/Rector/ClassLike/RemoveTypedPropertyNonMockDocblockRector/Fixture/fixture.php.inc +++ /dev/null @@ -1,32 +0,0 @@ - ------ - diff --git a/rules-tests/DeadCode/Rector/ClassLike/RemoveTypedPropertyNonMockDocblockRector/Fixture/skip_array_doc.php.inc b/rules-tests/DeadCode/Rector/ClassLike/RemoveTypedPropertyNonMockDocblockRector/Fixture/skip_array_doc.php.inc deleted file mode 100644 index da57dca6cc5..00000000000 --- a/rules-tests/DeadCode/Rector/ClassLike/RemoveTypedPropertyNonMockDocblockRector/Fixture/skip_array_doc.php.inc +++ /dev/null @@ -1,29 +0,0 @@ -structure = ['test']; - } else { - $this->structure = $this->some_mixed_function(); - } - } - - private function some_mixed_function(): mixed - { - return null; - } -} diff --git a/rules-tests/DeadCode/Rector/ClassLike/RemoveTypedPropertyNonMockDocblockRector/Fixture/skip_missing_property_type.php.inc b/rules-tests/DeadCode/Rector/ClassLike/RemoveTypedPropertyNonMockDocblockRector/Fixture/skip_missing_property_type.php.inc deleted file mode 100644 index 86de7e0178b..00000000000 --- a/rules-tests/DeadCode/Rector/ClassLike/RemoveTypedPropertyNonMockDocblockRector/Fixture/skip_missing_property_type.php.inc +++ /dev/null @@ -1,15 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/DeadCode/Rector/ClassLike/RemoveTypedPropertyNonMockDocblockRector/Source/RealType.php b/rules-tests/DeadCode/Rector/ClassLike/RemoveTypedPropertyNonMockDocblockRector/Source/RealType.php deleted file mode 100644 index b9a59add843..00000000000 --- a/rules-tests/DeadCode/Rector/ClassLike/RemoveTypedPropertyNonMockDocblockRector/Source/RealType.php +++ /dev/null @@ -1,8 +0,0 @@ -rule(RemoveTypedPropertyNonMockDocblockRector::class); -}; diff --git a/rules/DeadCode/Rector/ClassLike/RemoveTypedPropertyNonMockDocblockRector.php b/rules/DeadCode/Rector/ClassLike/RemoveTypedPropertyNonMockDocblockRector.php index 3bec4b1de46..af74b38a204 100644 --- a/rules/DeadCode/Rector/ClassLike/RemoveTypedPropertyNonMockDocblockRector.php +++ b/rules/DeadCode/Rector/ClassLike/RemoveTypedPropertyNonMockDocblockRector.php @@ -5,37 +5,18 @@ namespace Rector\DeadCode\Rector\ClassLike; use PhpParser\Node; -use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Stmt\Class_; -use PhpParser\Node\Stmt\Property; -use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode; -use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode; -use PHPStan\Type\ObjectType; -use PHPStan\Type\Type; -use PHPStan\Type\UnionType; -use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; -use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; -use Rector\DeadCode\PhpDoc\TagRemover\VarTagRemover; -use Rector\Enum\ClassName; +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; +use Rector\Exception\ShouldNotHappenException; use Rector\Rector\AbstractRector; -use Rector\StaticTypeMapper\StaticTypeMapper; -use Rector\ValueObject\PhpVersionFeature; -use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** - * @see \Rector\Tests\DeadCode\Rector\ClassLike\RemoveTypedPropertyNonMockDocblockRector\RemoveTypedPropertyNonMockDocblockRectorTest + * @deprecated This rule is deprecated as it has no real value, removing a single narrow @var docblock combination on a typed property. */ -final class RemoveTypedPropertyNonMockDocblockRector extends AbstractRector implements MinPhpVersionInterface +final class RemoveTypedPropertyNonMockDocblockRector extends AbstractRector implements DeprecatedInterface { - public function __construct( - private readonly VarTagRemover $varTagRemover, - private readonly StaticTypeMapper $staticTypeMapper, - private readonly PhpDocInfoFactory $phpDocInfoFactory - ) { - } - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition( @@ -79,73 +60,6 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - if (! $this->isObjectType($node, new ObjectType(ClassName::TEST_CASE_CLASS))) { - return null; - } - - $hasChanged = false; - - foreach ($node->getProperties() as $property) { - // not yet typed - if (! $property->type instanceof Node) { - continue; - } - - if (count($property->props) !== 1) { - continue; - } - - if (! $property->type instanceof FullyQualified) { - continue; - } - - if ($this->isObjectType($property->type, new ObjectType(ClassName::MOCK_OBJECT))) { - continue; - } - - $propertyDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property); - - if (! $this->isVarTagUnionTypeMockObject($propertyDocInfo, $property)) { - continue; - } - - // clear var docblock - if ($this->varTagRemover->removeVarTag($property)) { - $hasChanged = true; - } - } - - if (! $hasChanged) { - return null; - } - - return $node; - } - - public function provideMinPhpVersion(): int - { - return PhpVersionFeature::TYPED_PROPERTIES; - } - - private function isVarTagUnionTypeMockObject(PhpDocInfo $phpDocInfo, Property $property): bool - { - $varTagValueNode = $phpDocInfo->getVarTagValueNode(); - if (! $varTagValueNode instanceof VarTagValueNode) { - return false; - } - - if (! $varTagValueNode->type instanceof UnionTypeNode) { - return false; - } - - $varTagType = $this->staticTypeMapper->mapPHPStanPhpDocTypeNodeToPHPStanType($varTagValueNode->type, $property); - if (! $varTagType instanceof UnionType) { - return false; - } - - return array_any( - $varTagType->getTypes(), - fn (Type $unionedType): bool => $unionedType->isSuperTypeOf(new ObjectType(ClassName::MOCK_OBJECT))->yes() - ); + throw new ShouldNotHappenException(sprintf('"%s" is deprecated as it has no real value', self::class)); } } diff --git a/src/Config/Level/DeadCodeLevel.php b/src/Config/Level/DeadCodeLevel.php index dd68b6c251a..e1062f82deb 100644 --- a/src/Config/Level/DeadCodeLevel.php +++ b/src/Config/Level/DeadCodeLevel.php @@ -13,7 +13,6 @@ use Rector\DeadCode\Rector\BooleanAnd\RemoveAndTrueRector; use Rector\DeadCode\Rector\Cast\RecastingRemovalRector; use Rector\DeadCode\Rector\ClassConst\RemoveUnusedPrivateClassConstantRector; -use Rector\DeadCode\Rector\ClassLike\RemoveTypedPropertyNonMockDocblockRector; use Rector\DeadCode\Rector\ClassMethod\RemoveArgumentFromDefaultParentCallRector; use Rector\DeadCode\Rector\ClassMethod\RemoveDuplicatedReturnSelfDocblockRector; use Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector; @@ -126,7 +125,6 @@ final class DeadCodeLevel // prioritize safe belt on RemoveUseless*TagRector that registered previously first RemoveNullTagValueNodeRector::class, RemovePhpVersionIdCheckRector::class, - RemoveTypedPropertyNonMockDocblockRector::class, RemoveAlwaysTrueIfConditionRector::class, ReduceAlwaysFalseIfOrRector::class,