Add support for rename of @property

This commit is contained in:
TomasVotruba 2020-06-08 10:54:36 +02:00
parent 690e2e9546
commit f115fd6da6
5 changed files with 46 additions and 3 deletions

View File

@ -7,8 +7,9 @@ namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\TypeAwareTagValueNodeInterface;
final class AttributeAwarePropertyTagValueNode extends PropertyTagValueNode implements AttributeAwareNodeInterface
final class AttributeAwarePropertyTagValueNode extends PropertyTagValueNode implements AttributeAwareNodeInterface, TypeAwareTagValueNodeInterface
{
use AttributeTrait;
}

View File

@ -9,6 +9,7 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\ThrowsTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
@ -47,7 +48,8 @@ final class PhpDocNodeTraverser
private function isValueNodeWithType(PhpDocTagValueNode $phpDocTagValueNode): bool
{
return $phpDocTagValueNode instanceof ReturnTagValueNode ||
return $phpDocTagValueNode instanceof PropertyTagValueNode ||
$phpDocTagValueNode instanceof ReturnTagValueNode ||
$phpDocTagValueNode instanceof ParamTagValueNode ||
$phpDocTagValueNode instanceof VarTagValueNode ||
$phpDocTagValueNode instanceof ThrowsTagValueNode;

View File

@ -8,8 +8,10 @@ use PhpParser\Node;
use PHPStan\PhpDocParser\Ast\Node as PhpDocParserNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use Rector\BetterPhpDocParser\Ast\PhpDocNodeTraverser;
use Rector\PHPStan\Type\ShortenedObjectType;
use Rector\StaticTypeMapper\StaticTypeMapper;
final class DocBlockClassRenamer
@ -50,6 +52,12 @@ final class DocBlockClassRenamer
}
$staticType = $this->staticTypeMapper->mapPHPStanPhpDocTypeNodeToPHPStanType($node, $phpParserNode);
// make sure to compare FQNs
if ($staticType instanceof ShortenedObjectType) {
$staticType = new ObjectType($staticType->getFullyQualifiedName());
}
if (! $staticType->equals($oldType)) {
return $node;
}

View File

@ -102,7 +102,6 @@ final class DocBlockNameImporter
}
$staticType = $this->staticTypeMapper->mapPHPStanPhpDocTypeNodeToPHPStanType($docNode, $phpParserNode);
if (! $staticType instanceof FullyQualifiedObjectType) {
return $docNode;
}

View File

@ -0,0 +1,33 @@
<?php
namespace Rector\Renaming\Tests\Rector\Class_\RenameClassRector\Fixture;
use Rector\Renaming\Tests\Rector\Class_\RenameClassRector\Source\OldClass;
/**
* @property OldClass $some
* @property-read OldClass $someRead
* @property-write OldClass $someWrite
*/
class RenamePropertyRead
{
}
?>
-----
<?php
namespace Rector\Renaming\Tests\Rector\Class_\RenameClassRector\Fixture;
use Rector\Renaming\Tests\Rector\Class_\RenameClassRector\Source\NewClass;
/**
* @property \Rector\Renaming\Tests\Rector\Class_\RenameClassRector\Source\NewClass $some
* @property-read \Rector\Renaming\Tests\Rector\Class_\RenameClassRector\Source\NewClass $someRead
* @property-write \Rector\Renaming\Tests\Rector\Class_\RenameClassRector\Source\NewClass $someWrite
*/
class RenamePropertyRead
{
}
?>