Passed
Push — master ( 229462...d74785 )
by Andreas
02:20 queued 14s
created

PhpFileLoader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 32
ccs 15
cts 15
cp 1
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A load() 0 19 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Configuration\Loader;
6
7
use Doctrine\Migrations\Configuration\Configuration;
8
use Doctrine\Migrations\Configuration\Exception\FileNotFound;
9
use function assert;
10
use function file_exists;
11
use function is_array;
12
13
/**
14
 * @internal
15
 */
16
final class PhpFileLoader extends AbstractFileLoader
17
{
18
    /** @var ArrayLoader */
19
    private $arrayLoader;
20
21 12
    public function __construct()
22
    {
23 12
        $this->arrayLoader = new ArrayLoader();
24 12
    }
25
26
    /**
27
     * @param mixed $file
28
     */
29 10
    public function load($file) : Configuration
30
    {
31 10
        if (! file_exists($file)) {
32 1
            throw FileNotFound::new();
33
        }
34 9
        $config = require $file;
35 9
        if ($config instanceof Configuration) {
36 1
            return $config;
37
        }
38
39 8
        assert(is_array($config));
40 8
        if (isset($config['migrations_paths'])) {
41 3
            $config['migrations_paths'] = $this->getDirectoryRelativeToFile(
42 3
                $file,
43 3
                $config['migrations_paths']
44
            );
45
        }
46
47 8
        return $this->arrayLoader->load($config);
48
    }
49
}
50