mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-05 10:50:48 +00:00
6ef7f81fc3
c4dd05e2e3
[CodeQuality] Add StaticToSelfStaticMethodCallOnFinalClassRector (#5621)
44 lines
1.6 KiB
PHP
44 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\Doctrine\CodeQuality\AttributeTransformer\PropertyAttributeTransformer;
|
|
|
|
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 ManyToOneAttributeTransformer implements PropertyAttributeTransformerInterface
|
|
{
|
|
/**
|
|
* @readonly
|
|
* @var \Rector\PhpParser\Node\NodeFactory
|
|
*/
|
|
private $nodeFactory;
|
|
public function __construct(NodeFactory $nodeFactory)
|
|
{
|
|
$this->nodeFactory = $nodeFactory;
|
|
}
|
|
public function transform(EntityMapping $entityMapping, Property $property) : void
|
|
{
|
|
$manyToOneMapping = $entityMapping->matchManyToOnePropertyMapping($property);
|
|
if (!\is_array($manyToOneMapping)) {
|
|
return;
|
|
}
|
|
// handled by another mapper
|
|
unset($manyToOneMapping['joinColumns']);
|
|
// non existing
|
|
unset($manyToOneMapping['nullable']);
|
|
$args = $this->nodeFactory->createArgs($manyToOneMapping);
|
|
$property->attrGroups[] = AttributeFactory::createGroup($this->getClassName(), $args);
|
|
NodeValueNormalizer::ensureKeyIsClassConstFetch($args, EntityMappingKey::TARGET_ENTITY);
|
|
}
|
|
public function getClassName() : string
|
|
{
|
|
return MappingClass::MANY_TO_ONE;
|
|
}
|
|
}
|