Failed Conditions
Push — master ( f1c5e1...95a60e )
by GBProd
02:56
created

Handler::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace GBProd\ElasticaSpecification;
4
5
use Elastica\QueryBuilder;
6
use GBProd\ElasticaSpecification\ExpressionBuilder\AndXBuilder;
7
use GBProd\ElasticaSpecification\ExpressionBuilder\Builder;
8
use GBProd\ElasticaSpecification\ExpressionBuilder\NotBuilder;
9
use GBProd\ElasticaSpecification\ExpressionBuilder\OrXBuilder;
10
use GBProd\Specification\AndX;
11
use GBProd\Specification\Not;
12
use GBProd\Specification\OrX;
13
use GBProd\Specification\Specification;
14
15
/**
16
 * Handler for elastica specifications
17
 *
18
 * @author gbprod <[email protected]>
19
 */
20
class Handler
21
{
22
    /**
23
     * @param Registry
24
     */
25
    private $registry;
26
27
    /**
28
     * @param Registry $registry
29
     */
30 3
    public function __construct(Registry $registry)
31
    {
32 3
        $this->registry = $registry;
33
34 3
        $this->registry->register(AndX::class, new AndXBuilder($registry));
35 3
        $this->registry->register(OrX::class, new OrXBuilder($registry));
36 3
        $this->registry->register(Not::class, new NotBuilder($registry));
37 3
    }
38
39
    /**
40
     * handle specification for querybuilder
41
     *
42
     * @param Specification $spec
43
     * @param QueryBuilder  $qb
44
     *
45
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be \Elastica\Query\AbstractQuery?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
46
     */
47 1
    public function handle(Specification $spec, QueryBuilder $qb)
48
    {
49 1
        $builder = $this->registry->getBuilder($spec);
50
51 1
        return $builder->build($spec, $qb);
52
    }
53
54
    /**
55
     * Register a builder for specification
56
     *
57
     * @param string  $classname specification fully qualified classname
58
     * @param Builder $builder
59
     */
60 2
    public function registerBuilder($classname, Builder $builder)
61
    {
62 2
        $this->registry->register($classname, $builder);
63 2
    }
64
}
65