Failed Conditions
Push — master ( 4967a2...19868a )
by Jonathan
10s
created

ConnectionHelperLoader::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 4
cts 5
cp 0.8
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
crap 2.032
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\DBAL\Migrations\Configuration\Connection\Loader;
6
7
use Doctrine\DBAL\Connection;
8
use Doctrine\DBAL\Migrations\Configuration\Connection\ConnectionLoaderInterface;
9
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
10
use Symfony\Component\Console\Helper\HelperSet;
11
12
class ConnectionHelperLoader implements ConnectionLoaderInterface
13
{
14
    /** @var string */
15
    private $helperName;
16
17
    /** @var  HelperSet */
18
    private $helperSet;
19
20 38
    public function __construct(?HelperSet $helperSet = null, string $helperName)
21
    {
22 38
        $this->helperName = $helperName;
23
24 38
        if ($helperSet === null) {
25
            $helperSet = new HelperSet();
26
        }
27
28 38
        $this->helperSet = $helperSet;
29 38
    }
30
31
    /**
32
     * Read the input and return a Configuration, returns null if the config
33
     * is not supported.
34
     */
35 37
    public function chosen() : ?Connection
36
    {
37 37
        if ($this->helperSet->has($this->helperName)) {
38 13
            $connectionHelper = $this->helperSet->get($this->helperName);
39
40 13
            if ($connectionHelper instanceof ConnectionHelper) {
41 13
                return $connectionHelper->getConnection();
42
            }
43
        }
44
45 24
        return null;
46
    }
47
}
48