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

AbstractSelect   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A modify() 0 10 2
modifySelection() 0 1 ?
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