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

SingleConnectionProvider::getDefaultConnection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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