Failed Conditions
Push — master ( d8d7f6...ee5f34 )
by Jonathan
11s
created

ConnectionHelperLoader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 11
cts 12
cp 0.9167
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A chosen() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Configuration\Connection\Loader;
6
7
use Doctrine\DBAL\Connection;
8
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
9
use Doctrine\Migrations\Configuration\Connection\ConnectionLoaderInterface;
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