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

ConnectionRegistryConnection::setConnectionName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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