NotFactory::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

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