Handler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 51
ccs 13
cts 13
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A handle() 0 6 1
A registerFactory() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GBProd\ElasticaSpecification;
6
7
use Elastica\QueryBuilder;
8
use Elastica\Query\AbstractQuery;
9
use GBProd\ElasticaSpecification\QueryFactory\AndXFactory;
10
use GBProd\ElasticaSpecification\QueryFactory\Factory;
11
use GBProd\ElasticaSpecification\QueryFactory\NotFactory;
12
use GBProd\ElasticaSpecification\QueryFactory\OrXFactory;
13
use GBProd\Specification\AndX;
14
use GBProd\Specification\Not;
15
use GBProd\Specification\OrX;
16
use GBProd\Specification\Specification;
17
18
/**
19
 * Handler for elastica specifications
20
 *
21
 * @author gbprod <[email protected]>
22
 */
23
class Handler
24
{
25
    /**
26
     * @param Registry
27
     */
28
    private $registry;
29
30
    /**
31
     * @param QueryBuilder
32
     */
33
    private $qb;
34
35
    /**
36
     * @param Registry     $registry
37
     * @param QueryBuilder $qb
38
     */
39 3
    public function __construct(Registry $registry, QueryBuilder $qb)
40
    {
41 3
        $this->qb = $qb;
42 3
        $this->registry = $registry;
43
44 3
        $this->registry->register(AndX::class, new AndXFactory($registry));
45 3
        $this->registry->register(OrX::class, new OrXFactory($registry));
46 3
        $this->registry->register(Not::class, new NotFactory($registry));
47 3
    }
48
49
    /**
50
     * handle specification for querybuilder
51
     *
52
     * @param Specification $spec
53
     *
54
     * @return AbstractQuery
55
     */
56 1
    public function handle(Specification $spec)
57
    {
58 1
        $factory = $this->registry->getFactory($spec);
59
60 1
        return $factory->create($spec, $this->qb);
61
    }
62
63
    /**
64
     * Register a factory for specification
65
     *
66
     * @param string  $classname specification fully qualified classname
67
     * @param Factory $factory
68
     */
69 2
    public function registerFactory($classname, Factory $factory)
70
    {
71 2
        $this->registry->register($classname, $factory);
72 2
    }
73
}
74