Completed
Push — master ( 882947...a4a53d )
by Mike
13:52 queued 13:46
created

ArrayConnectionConfigurationLoader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 32
ccs 11
cts 12
cp 0.9167
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A chosen() 0 17 4
1
<?php
2
3
namespace Doctrine\DBAL\Migrations\Configuration\Connection\Loader;
4
5
use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\DriverManager;
7
use Doctrine\DBAL\Migrations\Configuration\Connection\ConnectionLoaderInterface;
8
9
class ArrayConnectionConfigurationLoader implements ConnectionLoaderInterface
10
{
11
    private $filename;
12
13 35
    public function __construct($filename)
14
    {
15 35
        $this->filename = $filename;
16 35
    }
17
18
    /**
19
     * read the input and return a Configuration, returns `false` if the config
20
     * is not supported
21
     * @return Connection|null
22
     */
23 35
    public function chosen()
24
    {
25 35
        if (empty($this->filename)) {
26 34
            return null;
27
        }
28
29 35
        if ( ! file_exists($this->filename)) {
30 34
            return null;
31
        }
32
33 1
        $params = include $this->filename;
34 1
        if ( ! is_array($params)) {
35
            throw new \InvalidArgumentException('The connection file has to return an array with database configuration parameters.');
36
        }
37
38 1
        return DriverManager::getConnection($params);
39
    }
40
}
41