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

SourcesRegistry   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 43
ccs 0
cts 29
cp 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A add() 0 6 2
A has() 0 4 1
A get() 0 4 1
A all() 0 4 1
A getIterator() 0 4 1
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