Failed Conditions
Pull Request — master (#911)
by Asmir
02:45
created

FormattedFile::setDefaultLoaders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1.048

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 17
ccs 7
cts 11
cp 0.6364
crap 1.048
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Configuration\Migration;
6
7
use Doctrine\Migrations\Configuration\Configuration;
8
use function count;
9
use function pathinfo;
10
use const PATHINFO_EXTENSION;
11
12
/**
13
 * @internal
14
 */
15
final class FormattedFile extends ConfigurationFile
16
{
17
    /** @var callable[] */
18
    private $loaders = [];
19
20 3
    private function setDefaultLoaders() : void
21
    {
22 3
        $this->loaders = [
23
            'json' => static function ($file) : ConfigurationLoader {
24
                return new JsonFile($file);
25 3
            },
26
            'php' => static function ($file) : ConfigurationLoader {
27 2
                return new PhpFile($file);
28 3
            },
29
            'xml' => static function ($file) : ConfigurationLoader {
30
                return new XmlFile($file);
31 3
            },
32
            'yaml' => static function ($file) : ConfigurationLoader {
33
                return new YamlFile($file);
34 3
            },
35
            'yml' => static function ($file) : ConfigurationLoader {
36
                return new YamlFile($file);
37 3
            },
38
        ];
39 3
    }
40
41 3
    public function getConfiguration() : Configuration
42
    {
43 3
        if (count($this->loaders) === 0) {
44 3
            $this->setDefaultLoaders();
45
        }
46
47 3
        $extension = pathinfo($this->file, PATHINFO_EXTENSION);
48 3
        if (! isset($this->loaders[$extension])) {
49 1
            throw Migration\Exception\InvalidConfigurationFormat::new($this->file);
0 ignored issues
show
Bug introduced by
The type Doctrine\Migrations\Conf...alidConfigurationFormat was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
50
        }
51
52 2
        return $this->loaders[$extension]($this->file)->getConfiguration();
53
    }
54
}
55