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\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