Completed
Push — master ( 17fbce...9c0ecb )
by Nikola
02:12
created

SourcesRegistry::has()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace RunOpenCode\ExchangeRate\Registry;
4
5
use RunOpenCode\ExchangeRate\Contract\SourceInterface;
6
use RunOpenCode\ExchangeRate\Contract\SourcesRegistryInterface;
7
use Traversable;
8
9
final class SourcesRegistry implements SourcesRegistryInterface
10
{
11
    private $sources;
12
13
    public function __construct(array $sources = array())
14
    {
15
        $this->sources = array();
16
17
        foreach ($sources as $source) {
18
            $this->add($source);
19
        }
20
    }
21
22
    public function add(SourceInterface $source)
23
    {
24
        if ($this->has($source->getName())) {
25
            throw new \RuntimeException(sprintf('Source "%s" is already registered.', $source->getName()));
26
        }
27
    }
28
29
    public function has($name)
30
    {
31
        return array_key_exists($name, $this->sources);
32
    }
33
34
    public function get($name)
35
    {
36
        return $this->sources[$name];
37
    }
38
39
    public function all()
40
    {
41
        return $this->sources;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function getIterator()
48
    {
49
        return new \ArrayIterator($this->sources);
50
    }
51
}
52