mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-05 10:50:48 +00:00
055cd31f66
2ff0f08bd7
[PHP 8.0] Add always class to AnnotationToAttribute to include string to ::class reference conversion (#5619)
35 lines
1.4 KiB
PHP
35 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\Doctrine\CodeQuality\AnnotationTransformer\PropertyAnnotationTransformer;
|
|
|
|
use PhpParser\Node\Stmt\Property;
|
|
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
|
|
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
|
|
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
|
use Rector\Doctrine\CodeQuality\Contract\PropertyAnnotationTransformerInterface;
|
|
use Rector\Doctrine\CodeQuality\DocTagNodeFactory;
|
|
use Rector\Doctrine\CodeQuality\ValueObject\EntityMapping;
|
|
use Rector\Doctrine\Enum\MappingClass;
|
|
final class IdColumnAnnotationTransformer implements PropertyAnnotationTransformerInterface
|
|
{
|
|
public function transform(EntityMapping $entityMapping, PhpDocInfo $propertyPhpDocInfo, Property $property) : void
|
|
{
|
|
$idMapping = $entityMapping->matchIdPropertyMapping($property);
|
|
if (!\is_array($idMapping)) {
|
|
return;
|
|
}
|
|
$arrayItemNodes = [];
|
|
$type = $idMapping['type'] ?? null;
|
|
if ($type) {
|
|
$arrayItemNodes[] = new ArrayItemNode(new StringNode($type), 'type');
|
|
}
|
|
$spacelessPhpDocTagNode = DocTagNodeFactory::createSpacelessPhpDocTagNode($arrayItemNodes, $this->getClassName());
|
|
$propertyPhpDocInfo->addPhpDocTagNode($spacelessPhpDocTagNode);
|
|
}
|
|
public function getClassName() : string
|
|
{
|
|
return MappingClass::COLUMN;
|
|
}
|
|
}
|