Completed
Pull Request — master (#1023)
by Asmir
02:45 queued 16s
created

ConnectionRegistryConnection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 28
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setConnectionName() 0 4 1
A getConnection() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Configuration\Connection;
6
7
use Doctrine\DBAL\Connection;
8
use Doctrine\Persistence\ConnectionRegistry;
9
use RuntimeException;
10
11
final class ConnectionRegistryConnection implements ConnectionLoader
12
{
13
    /** @var ConnectionRegistry */
14
    private $registry;
15
16
    /** @var string|null */
17
    private $connectionName;
18
19
    public function __construct(ConnectionRegistry $registry)
20
    {
21
        $this->registry = $registry;
22
    }
23
24
    public function setConnectionName(?string $name) : void
25
    {
26
        $this->connectionName = $name;
27
    }
28
29
    public function getConnection() : Connection
30
    {
31
        $connection = $this->registry->getConnection($this->connectionName);
32
        if (! $connection instanceof Connection) {
33
            throw new RuntimeException('The returned connection must be @todo');
34
        }
35
36
        return $connection;
37
    }
38
}
39