Failed Conditions
Push — master ( 10368b...49930d )
by Andreas
12:05
created

YamlConfiguration::doLoad()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4.128

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 8
cts 10
cp 0.8
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 4
nop 1
crap 4.128
1
<?php
2
3
namespace Doctrine\DBAL\Migrations\Configuration;
4
5
use Symfony\Component\Yaml\Yaml;
6
7
use Doctrine\DBAL\Migrations\MigrationException;
8
9
/**
10
 * Load migration configuration information from a YAML configuration file.
11
 *
12
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
13
 * @link        www.doctrine-project.org
14
 * @since       2.0
15
 * @author      Jonathan H. Wage <[email protected]>
16
 */
17
class YamlConfiguration extends AbstractFileConfiguration
18
{
19
    /**
20
     * @inheritdoc
21
     */
22 29
    protected function doLoad($file)
23
    {
24 29
        if ( ! class_exists(Yaml::class)) {
25
            throw MigrationException::yamlConfigurationNotAvailable();
26
        }
27
28 29
        $config = Yaml::parse(file_get_contents($file));
29
30 29
        if ( ! is_array($config)) {
31
            throw new \InvalidArgumentException('Not valid configuration.');
32
        }
33
34 29
        if (isset($config['migrations_directory'])) {
35 19
            $config['migrations_directory'] = $this->getDirectoryRelativeToFile($file, $config['migrations_directory']);
36
        }
37
38 29
        $this->setConfiguration($config);
39 26
    }
40
}
41