Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromDocblockSetUpDefinedRector\Fixture;

use PHPUnit\Framework\TestCase;
use Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromDocblockSetUpDefinedRector\Source\SomeDocblockType;

final class GenericTypeDoc extends TestCase
{
/**
* @var \Iterator<SomeType>
*/
private $someType;

protected function setUp(): void
{
$this->someType = $this->create('string');
}
}

?>
-----
<?php

namespace Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromDocblockSetUpDefinedRector\Fixture;

use PHPUnit\Framework\TestCase;
use Rector\Tests\TypeDeclaration\Rector\Class_\TypedPropertyFromDocblockSetUpDefinedRector\Source\SomeDocblockType;

final class GenericTypeDoc extends TestCase
{
/**
* @var \Iterator<SomeType>
*/
private \Iterator $someType;

protected function setUp(): void
{
$this->someType = $this->create('string');
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\DeadCode\PhpDoc\DeadVarTagValueNodeAnalyzer;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
use Rector\Rector\AbstractRector;
Expand All @@ -34,7 +35,8 @@ public function __construct(
private readonly ConstructorAssignDetector $constructorAssignDetector,
private readonly PhpDocInfoFactory $phpDocInfoFactory,
private readonly StaticTypeMapper $staticTypeMapper,
private readonly DocBlockUpdater $docBlockUpdater
private readonly DocBlockUpdater $docBlockUpdater,
private readonly DeadVarTagValueNodeAnalyzer $deadVarTagValueNodeAnalyzer
) {
}

Expand Down Expand Up @@ -145,10 +147,11 @@ public function refactor(Node $node): ?Node
continue;
}

$property->type = $nativePropertyTypeNode;

// remove var tag
$this->removeVarTag($propertyPhpDocInfo, $property);

$property->type = $nativePropertyTypeNode;
$hasChanged = true;
}

Expand All @@ -166,6 +169,16 @@ public function provideMinPhpVersion(): int

private function removeVarTag(PhpDocInfo $propertyPhpDocInfo, Property $property): void
{
$varTagValueNode = $propertyPhpDocInfo->getVarTagValueNode();

if (! $varTagValueNode instanceof VarTagValueNode) {
return;
}

if (! $this->deadVarTagValueNodeAnalyzer->isDead($varTagValueNode, $property)) {
return;
}

$propertyPhpDocInfo->removeByType(VarTagValueNode::class);
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($property);
}
Expand Down
Loading