NotFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 12 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