AbstractJoin   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 50
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A modify() 0 9 2
getJoinType() 0 1 ?
1
<?php
2
3
/**
4
 * This file is part of the Happyr Doctrine Specification package.
5
 *
6
 * (c) Tobias Nyholm <[email protected]>
7
 *     Kacper Gunia <[email protected]>
8
 *     Peter Gribanov <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Happyr\DoctrineSpecification\Query;
15
16
use Doctrine\ORM\QueryBuilder;
17
18
/**
19
 * @author Tobias Nyholm
20
 */
21
abstract class AbstractJoin implements QueryModifier
22
{
23
    /**
24
     * @var string
25
     */
26
    private $field;
27
28
    /**
29
     * @var string
30
     */
31
    private $newAlias;
32
33
    /**
34
     * @var string|null
35
     */
36
    private $dqlAlias;
37
38
    /**
39
     * @param string      $field
40
     * @param string      $newAlias
41
     * @param string|null $dqlAlias
42
     */
43
    public function __construct($field, $newAlias, $dqlAlias = null)
44
    {
45
        $this->field = $field;
46
        $this->newAlias = $newAlias;
47
        $this->dqlAlias = $dqlAlias;
48
    }
49
50
    /**
51
     * @param QueryBuilder $qb
52
     * @param string       $dqlAlias
53
     */
54
    public function modify(QueryBuilder $qb, $dqlAlias)
55
    {
56
        if (null !== $this->dqlAlias) {
57
            $dqlAlias = $this->dqlAlias;
58
        }
59
60
        $join = $this->getJoinType();
61
        $qb->$join(sprintf('%s.%s', $dqlAlias, $this->field), $this->newAlias);
62
    }
63
64
    /**
65
     * Return a join type (ie a function of QueryBuilder) like: "join", "innerJoin", "leftJoin".
66
     *
67
     * @return string
68
     */
69
    abstract protected function getJoinType();
70
}
71