Handler   A
last analyzed

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