rector/vendor/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/OrderByAttributeTransformer.php
Tomas Votruba 53742c371b Updated Rector to commit 70fa502a59dfb8f81011a46a456e1ccb4051be76
70fa502a59 [CodeQuality] Skip private static call from static:: on LocallyCalledStaticMethodToNonStaticRector (#5620)
2024-02-15 09:08:32 +00:00

43 lines
1.5 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\NodeFactory\AttributeFactory;
use Rector\Doctrine\CodeQuality\ValueObject\EntityMapping;
use Rector\Doctrine\Enum\MappingClass;
use Rector\PhpParser\Node\NodeFactory;
final class OrderByAttributeTransformer 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
{
$oneToManyMapping = $entityMapping->matchOneToManyPropertyMapping($property);
if (!\is_array($oneToManyMapping)) {
return;
}
// we handle OrderBy here only
if (!isset($oneToManyMapping[EntityMappingKey::ORDER_BY])) {
return;
}
$orderBy = $oneToManyMapping[EntityMappingKey::ORDER_BY];
$args = $this->nodeFactory->createArgs([$orderBy]);
$property->attrGroups[] = AttributeFactory::createGroup($this->getClassName(), $args);
}
public function getClassName() : string
{
return MappingClass::ORDER_BY;
}
}