FormattedFile::getConfiguration()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 9.8333
c 0
b 0
f 0
cc 3
nc 4
nop 0
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Configuration\Migration;
6
7
use Doctrine\Migrations\Configuration\Configuration;
8
use Doctrine\Migrations\Configuration\Migration\Exception\InvalidConfigurationFormat;
9
use function count;
10
use function pathinfo;
11
use const PATHINFO_EXTENSION;
12
13
/**
14
 * @internal
15
 */
16
final class FormattedFile extends ConfigurationFile
17
{
18
    /** @var callable[] */
19
    private $loaders = [];
20
21 4
    private function setDefaultLoaders() : void
22
    {
23 4
        $this->loaders = [
0 ignored issues
show
Documentation Bug introduced by
It seems like array('json' => static f...ion\YamlFile($file); }) of type array<string,object<Clos...ml":"object<Closure>"}> is incompatible with the declared type array<integer,callable> of property $loaders.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
24
            'json' => static function ($file) : ConfigurationLoader {
25
                return new JsonFile($file);
26 4
            },
27
            'php' => static function ($file) : ConfigurationLoader {
28 2
                return new PhpFile($file);
29 4
            },
30
            'xml' => static function ($file) : ConfigurationLoader {
31
                return new XmlFile($file);
32 4
            },
33
            'yaml' => static function ($file) : ConfigurationLoader {
34
                return new YamlFile($file);
35 4
            },
36
            'yml' => static function ($file) : ConfigurationLoader {
37 1
                return new YamlFile($file);
38 4
            },
39
        ];
40 4
    }
41
42 4
    public function getConfiguration() : Configuration
43
    {
44 4
        if (count($this->loaders) === 0) {
45 4
            $this->setDefaultLoaders();
46
        }
47
48 4
        $extension = pathinfo($this->file, PATHINFO_EXTENSION);
49 4
        if (! isset($this->loaders[$extension])) {
50 1
            throw InvalidConfigurationFormat::new($this->file);
51
        }
52
53 3
        return $this->loaders[$extension]($this->file)->getConfiguration();
54
    }
55
}
56