ResponseHandlerRegistry::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace LAG\SmokerBundle\Response\Registry;
4
5
use LAG\SmokerBundle\Contracts\Response\Handler\ResponseHandlerInterface;
6
use LAG\SmokerBundle\Exception\Exception;
7
8
class ResponseHandlerRegistry
9
{
10
    protected $registry = [];
11
12 1
    public function add(string $name, ResponseHandlerInterface $handler): void
13
    {
14 1
        $this->registry[$name] = $handler;
15 1
    }
16
17
    /**
18
     * @throws Exception
19
     */
20 1
    public function get(string $name): ResponseHandlerInterface
21
    {
22 1
        if (!$this->has($name)) {
23 1
            throw new Exception('The response handler "'.$name.'" is not registered');
24
        }
25
26 1
        return $this->registry[$name];
27
    }
28
29 1
    public function has(string $name): bool
30
    {
31 1
        return key_exists($name, $this->registry);
32
    }
33
34
    /**
35
     * @return ResponseHandlerInterface[]
36
     */
37 1
    public function all(): array
38
    {
39 1
        return $this->registry;
40
    }
41
}
42