rector/vendor/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/JoinTableAttributeTransformer.php
Tomas Votruba 6cbc8ec497 Updated Rector to commit 068799f59b289bef06b9c1f384df4301b19e726e
068799f59b [Performance] Early skip func call name on ClassRenamer (#5837)
2024-04-21 13:28:31 +00:00

46 lines
1.7 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\Enum\EntityMappingKey;
use Rector\Doctrine\CodeQuality\Helper\NodeValueNormalizer;
use Rector\Doctrine\CodeQuality\NodeFactory\AttributeFactory;
use Rector\Doctrine\CodeQuality\ValueObject\EntityMapping;
use Rector\Doctrine\Enum\MappingClass;
use Rector\PhpParser\Node\NodeFactory;
final class JoinTableAttributeTransformer 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
{
$joinTableMapping = $entityMapping->matchManyToManyPropertyMapping($property)['joinTable'] ?? null;
if (!\is_array($joinTableMapping)) {
return;
}
// handled by another mapper
unset($joinTableMapping['joinColumns'], $joinTableMapping['inverseJoinColumns']);
$args = $this->nodeFactory->createArgs($joinTableMapping);
$property->attrGroups[] = AttributeFactory::createGroup($this->getClassName(), $args);
NodeValueNormalizer::ensureKeyIsClassConstFetch($args, EntityMappingKey::TARGET_ENTITY);
}
public function getClassName() : string
{
return MappingClass::JOIN_TABLE;
}
}