Failed Conditions
Pull Request — 2.10.x (#4011)
by
unknown
03:07
created

SingleConnectionProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
dl 0
loc 26
ccs 0
cts 15
cp 0
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getConnection() 0 7 2
A getDefaultConnection() 0 3 1
A __construct() 0 4 1
1
<?php
2
3
namespace Doctrine\DBAL\Tools\Console\ConnectionProvider;
4
5
use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\Tools\Console\ConnectionNotFound;
7
use Doctrine\DBAL\Tools\Console\ConnectionProvider;
8
use function sprintf;
9
10
class SingleConnectionProvider implements ConnectionProvider
11
{
12
    /** @var Connection */
13
    private $connection;
14
15
    /** @var string */
16
    private $defaultConnectionName;
17
18
    public function __construct(Connection $connection, string $defaultConnectionName = 'default')
19
    {
20
        $this->connection            = $connection;
21
        $this->defaultConnectionName = $defaultConnectionName;
22
    }
23
24
    public function getDefaultConnection() : Connection
25
    {
26
        return $this->connection;
27
    }
28
29
    public function getConnection(string $name) : Connection
30
    {
31
        if ($name !== $this->defaultConnectionName) {
32
            throw new ConnectionNotFound(sprintf('Connection with name "%s" does not exist.', $name));
33
        }
34
35
        return $this->connection;
36
    }
37
}
38