Completed
Push — master ( 30910b...098427 )
by GBProd
02:29
created

AndXBuilder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace GBProd\ElasticaSpecification\ExpressionBuilder;
4
5
use Elastica\QueryBuilder;
6
use GBProd\ElasticaSpecification\Registry;
7
use GBProd\Specification\AndX;
8
use GBProd\Specification\Specification;
9
10
/**
11
 * Expression Builder for AndX specification
12
 *
13
 * @author gbprod <[email protected]>
14
 */
15
class AndXBuilder implements Builder
16
{
17
    /**
18
     * @var Registry
19
     */
20
    private $registry;
21
22
    /**
23
     * @param Registry $registry
24
     */
25 3
    public function __construct(Registry $registry)
26
    {
27 3
        $this->registry = $registry;
28 3
    }
29
30
    /**
31
     * {inheritdoc}
32
     */
33 2
    public function build(Specification $spec, QueryBuilder $qb)
34
    {
35 2
        if (!$spec instanceof AndX) {
36 1
            throw new \InvalidArgumentException();
37
        }
38
39 1
        $firstPartBuilder  = $this->registry->getBuilder($spec->getFirstPart());
40 1
        $secondPartBuilder = $this->registry->getBuilder($spec->getFirstPart());
41
42 1
        return $qb->query()->bool()
43 1
            ->addMust($firstPartBuilder->build($spec->getFirstPart(), $qb))
44 1
            ->addMust($secondPartBuilder->build($spec->getSecondPart(), $qb))
45
        ;
46
    }
47
}
48