Failed Conditions
Pull Request — master (#632)
by Michael
02:44
created

YamlConfiguration::doLoad()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4.0961

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 4
nop 1
dl 0
loc 20
ccs 9
cts 11
cp 0.8182
crap 4.0961
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Configuration;
6
7
use Doctrine\Migrations\MigrationException;
8
use Symfony\Component\Yaml\Yaml;
9
use function class_exists;
10
use function file_get_contents;
11
use function is_array;
12
13
class YamlConfiguration extends AbstractFileConfiguration
14
{
15
    /**
16
     * @inheritdoc
17
     */
18 29
    protected function doLoad(string $file) : void
19
    {
20 29
        if (! class_exists(Yaml::class)) {
21
            throw MigrationException::yamlConfigurationNotAvailable();
22
        }
23
24 29
        $config = Yaml::parse(file_get_contents($file));
25
26 29
        if (! is_array($config)) {
27
            throw MigrationException::configurationNotValid('Configuration is not valid YAML.');
28
        }
29
30 29
        if (isset($config['migrations_directory'])) {
31 19
            $config['migrations_directory'] = $this->getDirectoryRelativeToFile(
32 19
                $file,
33 19
                $config['migrations_directory']
34
            );
35
        }
36
37 29
        $this->setConfiguration($config);
38 26
    }
39
}
40