mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-01 00:40:52 +00:00
055cd31f66
2ff0f08bd7
[PHP 8.0] Add always class to AnnotationToAttribute to include string to ::class reference conversion (#5619)
49 lines
2.0 KiB
PHP
49 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\Doctrine\CodeQuality\AnnotationTransformer\ClassAnnotationTransformer;
|
|
|
|
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
|
|
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
|
use Rector\Doctrine\CodeQuality\Contract\ClassAnnotationTransformerInterface;
|
|
use Rector\Doctrine\CodeQuality\DocTagNodeFactory;
|
|
use Rector\Doctrine\CodeQuality\Helper\NodeValueNormalizer;
|
|
use Rector\Doctrine\CodeQuality\Utils\CaseStringHelper;
|
|
use Rector\Doctrine\CodeQuality\ValueObject\EntityMapping;
|
|
final class SoftDeletableClassAnnotationTransformer implements ClassAnnotationTransformerInterface
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
private const SOFT_DELETEABLE = 'soft_deleteable';
|
|
public function transform(EntityMapping $entityMapping, PhpDocInfo $classPhpDocInfo) : void
|
|
{
|
|
$classMapping = $entityMapping->getClassMapping();
|
|
$softDeletableMapping = $classMapping['gedmo'][self::SOFT_DELETEABLE] ?? null;
|
|
if (!\is_array($softDeletableMapping)) {
|
|
return;
|
|
}
|
|
$arrayItemNodes = $this->createArrayItemNodes($softDeletableMapping);
|
|
$spacelessPhpDocTagNode = DocTagNodeFactory::createSpacelessPhpDocTagNode($arrayItemNodes, $this->getClassName());
|
|
$classPhpDocInfo->addPhpDocTagNode($spacelessPhpDocTagNode);
|
|
}
|
|
public function getClassName() : string
|
|
{
|
|
return 'Gedmo\\Mapping\\Annotation\\SoftDeleteable';
|
|
}
|
|
/**
|
|
* @param array<string, mixed> $softDeletableMapping
|
|
* @return ArrayItemNode[]
|
|
*/
|
|
private function createArrayItemNodes(array $softDeletableMapping) : array
|
|
{
|
|
$arrayItemNodes = [];
|
|
foreach ($softDeletableMapping as $fieldKey => $fieldValueNode) {
|
|
$fieldKey = CaseStringHelper::camelCase($fieldKey);
|
|
$fieldValueNode = NodeValueNormalizer::normalize($fieldValueNode);
|
|
$arrayItemNodes[] = new ArrayItemNode($fieldValueNode, $fieldKey);
|
|
}
|
|
return $arrayItemNodes;
|
|
}
|
|
}
|