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

ArrayConnectionConfigurationLoader::chosen()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4.0218

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 8
cts 9
cp 0.8889
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 4
nop 0
crap 4.0218
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