Completed
Push — master ( 88c361...c3d442 )
by GBProd
05:04
created

NotFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 7
cts 7
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
namespace GBProd\DoctrineSpecification\QueryFactory;
4
5
use GBProd\DoctrineSpecification\Registry;
6
use GBProd\Specification\Not;
7
use GBProd\Specification\Specification;
8
use Doctrine\ORM\QueryBuilder;
9
10
/**
11
 * Factory for Not specification
12
 *
13
 * @author gbprod <[email protected]>
14
 */
15
class NotFactory implements Factory
16
{
17
    /**
18
     * @var Registry
19
     */
20
    private $registry;
21
22
    /**
23
     * @param Registry $registry
24
     */
25 7
    public function __construct(Registry $registry)
26
    {
27 7
        $this->registry = $registry;
28 7
    }
29
30
    /**
31
     * {inheritdoc}
32
     */
33 3
    public function create(Specification $spec, QueryBuilder $qb)
34
    {
35 3
        if (!$spec instanceof Not) {
36 1
            throw new \InvalidArgumentException();
37
        }
38
39 2
        $factory = $this->registry->getFactory($spec->getWrappedSpecification());
40
41 2
        return $qb->expr()->not(
42 2
            $factory->create($spec->getWrappedSpecification(), $qb)
43 2
        );
44
    }
45
}
46