AbstractSelect   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 37
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A modify() 0 10 2
modifySelection() 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
use Happyr\DoctrineSpecification\Query\Selection\ArgumentToSelectionConverter;
18
use Happyr\DoctrineSpecification\Query\Selection\Selection;
19
20
abstract class AbstractSelect implements QueryModifier
21
{
22
    /**
23
     * @var Selection[]
24
     */
25
    private $selections;
26
27
    /**
28
     * @param mixed $field
29
     */
30
    public function __construct($field)
31
    {
32
        // NEXT_MAJOR: use variable-length argument lists (...$fields)
33
        $this->selections = is_array($field) ? $field : func_get_args();
34
    }
35
36
    /**
37
     * @param QueryBuilder $qb
38
     * @param string       $dqlAlias
39
     */
40
    public function modify(QueryBuilder $qb, $dqlAlias)
41
    {
42
        $selections = [];
43
        foreach ($this->selections as $selection) {
44
            $selection = ArgumentToSelectionConverter::toSelection($selection);
45
            $selections[] = $selection->transform($qb, $dqlAlias);
46
        }
47
48
        $this->modifySelection($qb, $selections);
49
    }
50
51
    /**
52
     * @param QueryBuilder $qb
53
     * @param string[]     $selections
54
     */
55
    abstract protected function modifySelection(QueryBuilder $qb, array $selections);
56
}
57