Completed
Push — master ( fd0133...375486 )
by Beniamin
02:35
created

ConnectionManager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 85.71%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerConnection() 0 4 1
A getConnection() 0 8 3
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\SQLBuilder\Connection;
13
14
/**
15
 * @author Beniamin Jonatan Šimko <[email protected]>
16
 */
17
class ConnectionManager implements ConnectionManagerInterface
18
{
19
    /**
20
     * @var array
21
     */
22
    private $connections = [];
23
24
    /**
25
     * @inheritdoc
26
     */
27 2
    public function registerConnection(ConnectionInterface $connection, $name = 'default')
28
    {
29 2
        $this->connections[$name] = $connection;
30 2
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35 2
    public function getConnection($name = null)
36
    {
37 2
        if (0 === count($this->connections)) {
38
            return new NullConnection();
39
        }
40
41 2
        return $name ? $this->connections[$name] : reset($this->connections);
42
    }
43
}