Completed
Push — 1.0 ( 75b22b...f155d9 )
by Peter
15:56 queued 05:56
created

AbstractSelect::modify()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace Happyr\DoctrineSpecification\Query;
4
5
use Doctrine\ORM\QueryBuilder;
6
use Happyr\DoctrineSpecification\Query\Selection\ArgumentToSelectionConverter;
7
use Happyr\DoctrineSpecification\Query\Selection\Selection;
8
9
abstract class AbstractSelect implements QueryModifier
10
{
11
    /**
12
     * @var Selection[]
13
     */
14
    private $selections;
15
16
    /**
17
     * @param mixed $field
18
     */
19
    public function __construct($field)
20
    {
21
        $this->selections = is_array($field) ? $field : func_get_args();
22
    }
23
24
    /**
25
     * @param QueryBuilder $qb
26
     * @param string       $dqlAlias
27
     */
28
    public function modify(QueryBuilder $qb, $dqlAlias)
29
    {
30
        $selections = [];
31
        foreach ($this->selections as $selection) {
32
            $selection = ArgumentToSelectionConverter::toSelection($selection);
33
            $selections[] = $selection->transform($qb, $dqlAlias);
34
        }
35
36
        $this->modifySelection($qb, $selections);
37
    }
38
39
    /**
40
     * @param QueryBuilder $qb
41
     * @param string[]     $selections
42
     */
43
    abstract protected function modifySelection(QueryBuilder $qb, array $selections);
44
}
45