OneLevelRelationHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A filterParameter() 0 12 1
A filterWhereClause() 0 11 1
A relationJoin() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Bugloos\QueryFilterBundle\FilterHandler;
6
7
use Bugloos\QueryFilterBundle\FilterHandler\Contract\AbstractFilterHandler;
8
use Bugloos\QueryFilterBundle\FilterHandler\Contract\WithRelationInterface;
9
use Bugloos\QueryFilterBundle\TypeHandler\Factory\TypeFactory;
10
use ReflectionException;
11
12
/**
13
 * @author Milad Ghofrani <[email protected]>
14
 */
15
class OneLevelRelationHandler extends AbstractFilterHandler implements WithRelationInterface
16
{
17
    /**
18
     * @throws ReflectionException
19
     */
20
    public function filterParameter($rootAlias, $rootClass, $relationsAndFieldName, $type): string
21
    {
22
        [$relationAlias, $relationField] = $relationsAndFieldName;
23
24
        $this->validateRelationNames($relationAlias, $rootClass);
25
26
        $relationClass = $this->getRelationClass($rootClass, $relationAlias);
27
        $this->validateFieldNames($relationField, $relationClass);
28
29
        $this->fieldType = $this->getFieldTypeFromAnnotation($relationField, $relationClass);
30
31
        return $this->createParameterName($relationAlias, $relationField);
32
    }
33
34
    public function filterWhereClause(
35
        $rootAlias,
36
        $relationsAndFieldName,
37
        $filterParameter,
38
        $strategy,
39
        $value
40
    ): string {
41
        [$relationAlias, $relationField] = $relationsAndFieldName;
42
43
        return TypeFactory::createTypeHandler($this->fieldType)
44
            ->filterWhereClause($relationAlias, $relationField, $filterParameter, $strategy, $value)
45
        ;
46
    }
47
48
    public function relationJoin($relationJoins, $rootAlias, $rootClass, $relationsAndFieldName): array
49
    {
50
        [$relationAlias] = $relationsAndFieldName;
51
52
        return $this->addRelationJoin($relationJoins, $rootAlias, $relationAlias);
53
    }
54
}
55