Failed Conditions
Push — master ( ee57de...f1c5e1 )
by GBProd
02:44
created

NotBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 31
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A build() 0 12 2
1
<?php
2
3
namespace GBProd\ElasticaSpecification\ExpressionBuilder;
4
5
use Elastica\QueryBuilder;
6
use GBProd\ElasticaSpecification\Registry;
7
use GBProd\Specification\Not;
8
use GBProd\Specification\Specification;
9
10
/**
11
 * Expression Builder for Not specification
12
 *
13
 * @author gbprod <[email protected]>
14
 */
15
class NotBuilder 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 Not) {
36 1
            throw new \InvalidArgumentException();
37
        }
38
39 1
        $firstPartBuilder  = $this->registry->getBuilder($spec->getWrappedSpecification());
40
41 1
        return $qb->query()->bool()
42 1
            ->addMustNot($firstPartBuilder->build($spec->getWrappedSpecification(), $qb))
43 1
        ;
44
    }
45
}
46