Completed
Push — master ( a017c2...285708 )
by GBProd
02:17
created

Handler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 44
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

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