OrXFactory::__construct()   A
last analyzed

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
declare(strict_types=1);
4
5
6
namespace GBProd\ElasticaSpecification\QueryFactory;
7
8
use Elastica\QueryBuilder;
9
use GBProd\ElasticaSpecification\Registry;
10
use GBProd\Specification\OrX;
11
use GBProd\Specification\Specification;
12
13
/**
14
 * Factory for OrX specification
15
 *
16
 * @author gbprod <[email protected]>
17
 */
18 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...
19
{
20
    /**
21
     * @var Registry
22
     */
23
    private $registry;
24
25
    /**
26
     * @param Registry $registry
27
     */
28 6
    public function __construct(Registry $registry)
29
    {
30 6
        $this->registry = $registry;
31 6
    }
32
33
    /**
34
     * {inheritdoc}
35
     */
36 2
    public function create(Specification $spec, QueryBuilder $qb)
37
    {
38 2
        if (!$spec instanceof OrX) {
39 1
            throw new \InvalidArgumentException();
40
        }
41
42 1
        $firstPartFactory  = $this->registry->getFactory($spec->getFirstPart());
43 1
        $secondPartFactory = $this->registry->getFactory($spec->getSecondPart());
44
45 1
        return $qb->query()->bool()
46 1
            ->addShould($firstPartFactory->create($spec->getFirstPart(), $qb))
47 1
            ->addShould($secondPartFactory->create($spec->getSecondPart(), $qb))
48
        ;
49
    }
50
}
51