Completed
Push — master ( becf03...491f37 )
by Rafael
08:53
created

OrderByRelatedField   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 6
c 1
b 0
f 0
dl 0
loc 12
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 7 1
1
<?php
2
/*******************************************************************************
3
 *  This file is part of the GraphQL Bundle package.
4
 *
5
 *  (c) YnloUltratech <[email protected]>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 ******************************************************************************/
10
11
namespace Ynlo\GraphQLBundle\OrderBy\Common;
12
13
use Doctrine\ORM\QueryBuilder;
14
use Ynlo\GraphQLBundle\Model\OrderBy;
15
use Ynlo\GraphQLBundle\OrderBy\OrderByContext;
16
use Ynlo\GraphQLBundle\OrderBy\OrderByInterface;
17
18
class OrderByRelatedField implements OrderByInterface
19
{
20
    /**
21
     * @inheritDoc
22
     */
23
    public function __invoke(OrderByContext $context, QueryBuilder $qb, $alias, OrderBy $orderBy)
24
    {
25
        $column = $orderBy->getField();
26
        [$relation, $column] = explode('.', $column);
27
        $childAlias = 'orderBy'.ucfirst($relation);
28
        $qb->leftJoin("{$alias}.{$relation}", $childAlias);
29
        $qb->addOrderBy("$childAlias.$column", $orderBy->getDirection());
30
    }
31
}
32