SourceRegistry::add()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Bankiru\Seo\Resolver;
4
5
use Bankiru\Seo\SourceInterface;
6
7
final class SourceRegistry
8
{
9
    /** @var SourceInterface[] */
10
    private $sources = [];
11
12
    /**
13
     * @return SourceInterface[]
14
     */
15
    public function all()
16
    {
17
        return $this->sources;
18
    }
19
20
    /**
21
     * @param string          $key
22
     * @param SourceInterface $source
23
     */
24 1
    public function add($key, SourceInterface $source)
25
    {
26 1
        $this->sources[$key] = $source;
27 1
    }
28
29
    /**
30
     * @param string $key
31
     *
32
     * @return bool
33
     */
34 1
    public function has($key)
35
    {
36 1
        return array_key_exists($key, $this->sources);
37
    }
38
39
    /**
40
     * @param string $key
41
     *
42
     * @return SourceInterface
43
     * @throws \OutOfBoundsException
44
     */
45 1
    public function get($key)
46
    {
47 1
        if (!$this->has($key)) {
48
            throw new \OutOfBoundsException('Source not found: '.$key);
49
        }
50
51 1
        return $this->sources[$key];
52
    }
53
}
54
55