Passed
Pull Request — master (#739)
by Michael
02:38
created

JsonConfiguration   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A doLoad() 0 20 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Configuration;
6
7
use Doctrine\Migrations\Configuration\Exception\JsonNotValid;
8
use const JSON_ERROR_NONE;
9
use function assert;
10
use function file_get_contents;
11
use function json_decode;
12
use function json_last_error;
13
14
/**
15
 * The YamlConfiguration class is responsible for loading migration configuration information from a JSON file.
16
 *
17
 * @internal
18
 */
19
class JsonConfiguration extends AbstractFileConfiguration
20
{
21
    /** @inheritdoc */
22 22
    protected function doLoad(string $file) : void
23
    {
24 22
        $contents = file_get_contents($file);
25
26 22
        assert($contents !== false);
27
28 22
        $config = json_decode($contents, true);
29
30 22
        if (json_last_error() !== JSON_ERROR_NONE) {
31 1
            throw JsonNotValid::new();
32
        }
33
34 21
        if (isset($config['migrations_directory'])) {
35 14
            $config['migrations_directory'] = $this->getDirectoryRelativeToFile(
36 14
                $file,
37 14
                $config['migrations_directory']
38
            );
39
        }
40
41 21
        $this->setConfiguration($config);
42 18
    }
43
}
44