Completed
Push — master ( 8e5551...30910b )
by GBProd
02:20
created

Registry   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 4 1
A getBuilder() 0 11 2
1
<?php
2
3
namespace GBProd\ElasticaSpecification;
4
5
use GBProd\ElasticaSpecification\ExpressionBuilder\Builder;
6
use GBProd\Specification\Specification;
7
8
/**
9
 * Registry class for Expression builders
10
 *
11
 * @author gbprod <[email protected]>
12
 */
13
class Registry
14
{
15
    /**
16
     * @var array<Builder>
17
     */
18
    private $builders = [];
19
20
    /**
21
     * Register a builder
22
     *
23
     * @param string classname Fully qualified classname of the handled specification
24
     * @param Builder $builder
25
     */
26 1
    public function register($classname, Builder $builder)
27
    {
28 1
        $this->builders[$classname] = $builder;
29 1
    }
30
31
    /**
32
     * Get registred builder for Specification
33
     *
34
     * @param Specification $spec
35
     *
36
     * @return Builder
37
     *
38
     * @throw OutOfRangeException if builder not found
39
     */
40 2
    public function getBuilder(Specification $spec)
41
    {
42 2
        if (!isset($this->builders[get_class($spec)])) {
43 1
            throw new \OutOfRangeException(sprintf(
44 1
                'Builder for Specification "%s" not registred',
45 1
                get_class($spec)
46 1
            ));
47
        }
48
49 1
        return $this->builders[get_class($spec)];
50
    }
51
}
52