Completed
Pull Request — master (#16)
by Arnaud
48:07 queued 29:02
created

RequirementsProviderRegistry::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LAG\SmokerBundle\Url\Requirements\Registry;
4
5
use LAG\SmokerBundle\Exception\Exception;
6
use LAG\SmokerBundle\Contracts\Requirements\Provider\RequirementsProviderInterface;
7
8
class RequirementsProviderRegistry
9
{
10
    protected $registry = [];
11
12
    /**
13
     * @param string                        $name
14
     * @param RequirementsProviderInterface $provider
15
     */
16
    public function add(string $name, RequirementsProviderInterface $provider): void
17
    {
18
        $this->registry[$name] = $provider;
19
    }
20
21
    /**
22
     * @param string $name
23
     *
24
     * @return RequirementsProviderInterface
25
     *
26
     * @throws Exception
27
     */
28
    public function get(string $name): RequirementsProviderInterface
29
    {
30
        if (!$this->has($name)) {
31
            throw new Exception('The requirements provider "'.$name.'" is not registered');
32
        }
33
34
        return $this->registry[$name];
35
    }
36
37
    /**
38
     * @param string $name
39
     *
40
     * @return bool
41
     */
42
    public function has(string $name): bool
43
    {
44
        return key_exists($name, $this->registry);
45
    }
46
47
    /**
48
     * @return RequirementsProviderInterface[]
49
     */
50
    public function all(): array
51
    {
52
        return $this->registry;
53
    }
54
}
55