TwoLevelRelationHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRelationJoin() 0 7 1
A getSortProperty() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Bugloos\QuerySortingBundle\SortingHandler;
6
7
use Bugloos\QuerySortingBundle\SortingHandler\Contract\AbstractSortingHandler;
8
use Bugloos\QuerySortingBundle\SortingHandler\Contract\WithRelationInterface;
9
10
/**
11
 * @author Milad Ghofrani <[email protected]>
12
 */
13
class TwoLevelRelationHandler extends AbstractSortingHandler implements WithRelationInterface
14
{
15
    public function getSortProperty($rootAlias, $rootClass, $relationsAndFieldName): string
16
    {
17
        [$relationAlias, $subRelationAlias, $subRelationField] = $relationsAndFieldName;
18
19
        $this->validateRelationNames($relationAlias, $rootClass);
20
21
        $relationClass = $this->getRelationClass($rootClass, $relationAlias);
22
        $this->validateRelationNames($subRelationAlias, $relationClass);
23
24
        $subRelationClass = $this->getRelationClass($relationClass, $subRelationAlias);
25
        $this->validateFieldNames($subRelationField, $subRelationClass);
26
27
        return $this->createOrderBySyntax($subRelationAlias, $subRelationField);
28
    }
29
30
    public function getRelationJoin($relationJoins, $rootAlias, $rootClass, $relationsAndFieldName): array
31
    {
32
        [$relationAlias, $subRelationAlias] = $relationsAndFieldName;
33
34
        $relationJoins = $this->addRelationJoin($relationJoins, $rootAlias, $relationAlias);
35
36
        return $this->addRelationJoin($relationJoins, $relationAlias, $subRelationAlias);
37
    }
38
}
39