Completed
Push — master ( 098427...ee57de )
by GBProd
04:07 queued 01:59
created

OrXBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 4
dl 33
loc 33
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A build() 14 14 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace GBProd\ElasticaSpecification\ExpressionBuilder;
4
5
use Elastica\QueryBuilder;
6
use GBProd\ElasticaSpecification\Registry;
7
use GBProd\Specification\OrX;
8
use GBProd\Specification\Specification;
9
10
/**
11
 * Expression Builder for OrX specification
12
 *
13
 * @author gbprod <[email protected]>
14
 */
15 View Code Duplication
class OrXBuilder implements Builder
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 3
    public function __construct(Registry $registry)
26
    {
27 3
        $this->registry = $registry;
28 3
    }
29
30
    /**
31
     * {inheritdoc}
32
     */
33 2
    public function build(Specification $spec, QueryBuilder $qb)
34
    {
35 2
        if (!$spec instanceof OrX) {
36 1
            throw new \InvalidArgumentException();
37
        }
38
39 1
        $firstPartBuilder  = $this->registry->getBuilder($spec->getFirstPart());
40 1
        $secondPartBuilder = $this->registry->getBuilder($spec->getFirstPart());
41
42 1
        return $qb->query()->bool()
43 1
            ->addShould($firstPartBuilder->build($spec->getFirstPart(), $qb))
44 1
            ->addShould($secondPartBuilder->build($spec->getSecondPart(), $qb))
45
        ;
46
    }
47
}
48