BaseRegistrar   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 6
c 2
b 1
f 1
lcom 1
cbo 0
dl 0
loc 44
ccs 15
cts 15
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 10 2
A isRegistred() 0 4 1
A resolve() 0 13 3
1
<?php
2
3
namespace Alfheim\Sanitizer\Registrar;
4
5
use InvalidArgumentException;
6
7
class BaseRegistrar implements RegistrarInterface
8
{
9
    /** @var array */
10
    protected $registrations = [];
11
12
    /**
13
     * {@inheritdoc}
14
     */
15 36
    public function register($name, $sanitizer)
16
    {
17 36
        if ($this->isRegistred($name)) {
18 4
            return false;
19
        }
20
21 36
        $this->registrations[$name] = $sanitizer;
22
23 36
        return true;
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 40
    public function isRegistred($name)
30
    {
31 40
        return isset($this->registrations[$name]);
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 24
    public function resolve($name)
38
    {
39
        if (
40 24
            $this->isRegistred($name) &&
41 21
            is_callable($this->registrations[$name])
42 18
        ) {
43 20
            return $this->registrations[$name];
44
        }
45
46 4
        throw new InvalidArgumentException(sprintf(
47 4
            'Could not resolve [%s] from the registrar.', $name
48 3
        ));
49
    }
50
}
51