Completed
Pull Request — master (#14)
by Pavel
03:40
created

ClientRegistry   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
dl 0
loc 65
c 0
b 0
f 0
wmc 7
lcom 1
cbo 0
ccs 12
cts 16
cp 0.75
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 8 2
A has() 0 4 1
A add() 0 8 2
A replace() 0 4 1
A all() 0 4 1
1
<?php
2
3
namespace Bankiru\Api\Doctrine;
4
5
use ScayTrase\Api\Rpc\RpcClientInterface;
6
7
final class ClientRegistry implements ClientRegistryInterface
8
{
9
    /** @var  RpcClientInterface[] */
10
    private $clients = [];
11
12
    /**
13
     * @param string $name
14
     *
15
     * @return RpcClientInterface
16
     * @throws \OutOfBoundsException
17
     */
18 18
    public function get($name)
19
    {
20 18
        if (!$this->has($name)) {
21
            throw new \OutOfBoundsException(sprintf('Client "%s" not registered', $name));
22
        }
23
24 18
        return $this->clients[$name];
25
    }
26
27
    /**
28
     * @param string $name
29
     *
30
     * @return bool
31
     */
32 18
    public function has($name)
33
    {
34 18
        return array_key_exists($name, $this->clients);
35
    }
36
37
    /**
38
     * @param string             $name
39
     * @param RpcClientInterface $client
40
     *
41
     * @return void
42
     * @throws \InvalidArgumentException
43
     */
44 18
    public function add($name, RpcClientInterface $client)
45
    {
46 18
        if ($this->has($name)) {
47
            throw new \InvalidArgumentException();
48
        }
49
50 18
        $this->replace($name, $client);
51 18
    }
52
53
    /**
54
     * @param string             $name
55
     * @param RpcClientInterface $client
56
     *
57
     * @return void
58
     */
59 18
    public function replace($name, RpcClientInterface $client)
60
    {
61 18
        $this->clients[$name] = $client;
62 18
    }
63
64
    /**
65
     * @return RpcClientInterface[]
66
     */
67
    public function all()
68
    {
69
        return $this->clients;
70
    }
71
}
72