NotFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
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\DoctrineSpecification\QueryFactory;
6
7
use Doctrine\ORM\QueryBuilder;
8
use GBProd\DoctrineSpecification\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 7
    public function __construct(Registry $registry)
28
    {
29 7
        $this->registry = $registry;
30 7
    }
31
32
    /**
33
     * {inheritdoc}
34
     */
35 3
    public function create(Specification $spec, QueryBuilder $qb)
36
    {
37 3
        if (!$spec instanceof Not) {
38 1
            throw new \InvalidArgumentException();
39
        }
40
41 2
        $factory = $this->registry->getFactory($spec->getWrappedSpecification());
42
43 2
        return $qb->expr()->not(
44 2
            $factory->create($spec->getWrappedSpecification(), $qb)
45
        );
46
    }
47
}
48