Completed
Pull Request — develop (#535)
by Bastian
14:26 queued 09:46
created

Registry   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 48
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 6 1
A get() 0 8 2
A has() 0 4 1
1
<?php
2
/**
3
 * Registry
4
 */
5
6
namespace Graviton\ProxyBundle\Service\Source;
7
8
use Graviton\ProxyBundle\Exception\RegistryException;
9
10
/**
11
 * Class Registry
12
 *
13
 * @package Graviton\ProxyBundle\Service\Source
14
 * @author  List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
15
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
16
 * @link    http://swisscom.ch
17
 */
18
class Registry
19
{
20
    /** @var array  */
21
    public $sources = [];
22
23
    /**
24
     * Adds a proxy source to the registry.
25
     *
26
     * @param SourceInterface $source The source to be registered.
27
     * @param string          $alias  The identifier the source shall be find by.
28
     *
29
     * @return Registry
30
     */
31
    public function add(SourceInterface $source, $alias)
32
    {
33
        $this->sources[$alias] = $source;
34
35
        return $this;
36
    }
37
38
    /**
39
     * Finds the source identified by the given id in the registry;
40
     *
41
     * @param string $name Identifier of the source to be returned.
42
     *
43
     * @return SourceInterface
44
     */
45
    public function get($name)
46
    {
47
        if (!empty($this->sources[$name])) {
48
            return $this->sources[$name];
49
        }
50
51
        throw new RegistryException('There is no source registered matching the given identifyer ('. $name .')');
52
    }
53
54
    /**
55
     * Indicates if the given name represents a registered source.
56
     *
57
     * @param string $name
58
     *
59
     * @return bool
60
     */
61
    public function has($name)
62
    {
63
        return in_array($name, $this->sources);
64
    }
65
}
66