Passed
Branch master (10fdc5)
by Beniamin
02:43
created

ConnectionManager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A registerConnection() 0 4 1
A hasConnection() 0 4 1
A getConnection() 0 8 2
1
<?php
2
3
/**
4
 * This file is part of Phuria SQL Builder package.
5
 *
6
 * Copyright (c) 2016 Beniamin Jonatan Šimko
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Phuria\UnderQuery\Connection;
13
14
use Phuria\UnderQuery\Exception\ConnectionException;
15
16
/**
17
 * @author Beniamin Jonatan Šimko <[email protected]>
18
 */
19
class ConnectionManager implements ConnectionManagerInterface
20
{
21
    /**
22
     * @var array
23
     */
24
    private $connections = [];
25
26
    /**
27
     * @inheritdoc
28
     */
29 2
    public function registerConnection(ConnectionInterface $connection, $name = 'default')
30
    {
31 2
        $this->connections[$name] = $connection;
32 2
    }
33
34
    /**
35
     * @inheritdoc
36
     */
37 3
    public function hasConnection($name)
38
    {
39 3
        return array_key_exists($name, $this->connections);
40
    }
41
42
    /**
43
     * @inheritdoc
44
     */
45 3
    public function getConnection($name = 'default')
46
    {
47 3
        if (false === $this->hasConnection($name)) {
48 1
            throw ConnectionException::notRegistered($name);
49
        }
50
51 2
        return $this->connections[$name];
52
    }
53
}