Registry   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 72
ccs 0
cts 27
cp 0
rs 10
c 4
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getDefaultConnectionName() 0 4 1
A getConnection() 0 12 3
A getConnections() 0 4 1
A getConnectionNames() 0 4 1
1
<?php
2
3
namespace Brouzie\Sphinxy;
4
5
class Registry
6
{
7
    /**
8
     * @var Connection[]
9
     */
10
    private $connections;
11
12
    /**
13
     * @var string
14
     */
15
    private $defaultConnection;
16
17
    /**
18
     * @param Connection[] $connections
19
     * @param string $defaultConnection
20
     */
21
    public function __construct($connections, $defaultConnection)
22
    {
23
        $this->connections = $connections;
24
        $this->defaultConnection = $defaultConnection;
25
    }
26
27
    /**
28
     * Gets the default connection name.
29
     *
30
     * @return string
31
     */
32
    public function getDefaultConnectionName()
33
    {
34
        return $this->defaultConnection;
35
    }
36
37
    /**
38
     * Gets the named connection.
39
     *
40
     * @param string $name the connection name (null for the default one)
41
     *
42
     * @return Connection
43
     */
44
    public function getConnection($name = null)
45
    {
46
        if (null === $name) {
47
            $name = $this->defaultConnection;
48
        }
49
50
        if (!isset($this->connections[$name])) {
51
            throw new \InvalidArgumentException(sprintf('Sphinxy Connection named "%s" does not exist.', $name));
52
        }
53
54
        return $this->connections[$name];
55
    }
56
57
    /**
58
     * Gets an array of all registered connections.
59
     *
60
     * @return Connection[]
61
     */
62
    public function getConnections()
63
    {
64
        return $this->connections;
65
    }
66
67
    /**
68
     * Gets all connection names.
69
     *
70
     * @return array
71
     */
72
    public function getConnectionNames()
73
    {
74
        return array_keys($this->connections);
75
    }
76
}
77