rector/vendor/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/GedmoTimestampableAttributeTransformer.php
Tomas Votruba faf7fee8e4 Updated Rector to commit c4dd05e2e3ae6359ff4eb57ce7d7bd7619da139d
c4dd05e2e3 [CodeQuality] Add StaticToSelfStaticMethodCallOnFinalClassRector (#5621)
2024-02-15 14:52:20 +00:00

42 lines
1.5 KiB
PHP

<?php
declare (strict_types=1);
namespace Rector\Doctrine\CodeQuality\AttributeTransformer\PropertyAttributeTransformer;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Property;
use Rector\Doctrine\CodeQuality\Contract\PropertyAttributeTransformerInterface;
use Rector\Doctrine\CodeQuality\NodeFactory\AttributeFactory;
use Rector\Doctrine\CodeQuality\ValueObject\EntityMapping;
use Rector\Doctrine\Enum\MappingClass;
use Rector\PhpParser\Node\NodeFactory;
final class GedmoTimestampableAttributeTransformer implements PropertyAttributeTransformerInterface
{
/**
* @readonly
* @var \Rector\PhpParser\Node\NodeFactory
*/
private $nodeFactory;
public function __construct(NodeFactory $nodeFactory)
{
$this->nodeFactory = $nodeFactory;
}
/**
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
*/
public function transform(EntityMapping $entityMapping, $property) : void
{
$fieldPropertyMapping = $entityMapping->matchFieldPropertyMapping($property);
$timestampableMapping = $fieldPropertyMapping['gedmo']['timestampable'] ?? null;
if (!\is_array($timestampableMapping)) {
return;
}
$args = $this->nodeFactory->createArgs($timestampableMapping);
$property->attrGroups[] = AttributeFactory::createGroup($this->getClassName(), $args);
}
public function getClassName() : string
{
return MappingClass::GEDMO_TIMESTAMPABLE;
}
}