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

ConfigurationLoader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 33
ccs 18
cts 18
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addLoader() 0 3 1
A getLoader() 0 11 3
A setDefaultLoaders() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Configuration;
6
7
use Doctrine\Migrations\Configuration\Exception\UnknownLoader;
8
use Doctrine\Migrations\Configuration\Loader\ArrayLoader;
9
use Doctrine\Migrations\Configuration\Loader\JsonFileLoader;
10
use Doctrine\Migrations\Configuration\Loader\Loader;
11
use Doctrine\Migrations\Configuration\Loader\PhpFileLoader;
12
use Doctrine\Migrations\Configuration\Loader\XmlFileLoader;
13
use Doctrine\Migrations\Configuration\Loader\YamlFileLoader;
14
use function count;
15
16
/**
17
 * @internal
18
 */
19
class ConfigurationLoader
20
{
21
    /** @var Loader[] */
22
    private $loaders = [];
23
24 1
    public function addLoader(string $type, Loader $loader) : void
25
    {
26 1
        $this->loaders[$type] = $loader;
27 1
    }
28
29 2
    private function setDefaultLoaders() : void
30
    {
31 2
        $this->loaders = [
32 2
            'array' => new ArrayLoader(),
33 2
            'json' => new JsonFileLoader(),
34 2
            'php' => new PhpFileLoader(),
35 2
            'xml' => new XmlFileLoader(),
36 2
            'yaml' => new YamlFileLoader(),
37 2
            'yml' => new YamlFileLoader(),
38
        ];
39 2
    }
40
41 3
    public function getLoader(string $type) : Loader
42
    {
43 3
        if (count($this->loaders) === 0) {
44 2
            $this->setDefaultLoaders();
45
        }
46
47 3
        if (! isset($this->loaders[$type])) {
48 1
            throw UnknownLoader::new($type);
49
        }
50
51 2
        return $this->loaders[$type];
52
    }
53
}
54