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

OrXFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace GBProd\DoctrineSpecification\QueryFactory;
4
5
use GBProd\DoctrineSpecification\Registry;
6
use GBProd\Specification\OrX;
7
use GBProd\Specification\Specification;
8
use Doctrine\ORM\QueryBuilder;
9
10
/**
11
 * Factory for OrX specification
12
 *
13
 * @author gbprod <[email protected]>
14
 */
15 View Code Duplication
class OrXFactory implements Factory
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 OrX) {
36 1
            throw new \InvalidArgumentException();
37
        }
38
39 2
        $firstPartFactory  = $this->registry->getFactory($spec->getFirstPart());
40 2
        $secondPartFactory = $this->registry->getFactory($spec->getSecondPart());
41
42 2
        return $qb->expr()->orx(
43 2
            $firstPartFactory->create($spec->getFirstPart(), $qb),
44 2
            $secondPartFactory->create($spec->getSecondPart(), $qb)
45 2
        );
46
    }
47
}
48