BaseRegistrar::isRegistred()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
nc 1
cc 1
eloc 2
nop 1
crap 1
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