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

FormattedFile   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 38
ccs 16
cts 20
cp 0.8
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setDefaultLoaders() 0 17 1
A getConfiguration() 0 12 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 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