ConfigLoader   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 44
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A load() 0 6 1
A resolveLoader() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of the Yosymfony\Config-loader.
5
 *
6
 * (c) YoSymfony <http://github.com/yosymfony>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Yosymfony\ConfigLoader;
13
14
use Yosymfony\ConfigLoader\Exception\LoaderLoadException;
15
16
/**
17
 * Loads configuration sources
18
 *
19
 * @author Victor Puertas <[email protected]>
20
 */
21
class ConfigLoader
22
{
23
    /** @var LoaderResolverInterface */
24
    private $loaderResolver;
25
26
    /**
27
     * Constructor
28
     *
29
     * @param LoaderInterface[] $loaders List of loaders
30
     */
31
    public function __construct(array $loaders)
32
    {
33
        $this->loaderResolver = new LoaderResolver($loaders);
34
    }
35
36
    /**
37
     * Loads a resource such as a file or an inline configuration
38
     *
39
     * @param string $resource Filename or string representation
40
     * @param string $type     The resource type. Doesn't set this argument in
41
     *                         case of a filename passes as resource
42
     *
43
     * @return RepositoryInterface
44
     *
45
     * @throws LoaderLoadException If the loader not found
46
     */
47
    public function load($resource, $type = null) : RepositoryInterface
48
    {
49
        $repository = $this->resolveLoader($resource, $type)->load($resource, $type);
50
51
        return $repository;
52
    }
53
54
    private function resolveLoader($resource, $type = null) : LoaderInterface
55
    {
56
        $loader = $this->loaderResolver->resolveLoader($resource, $type);
57
58
        if ($loader === null) {
59
            throw new LoaderLoadException($resource, $type);
60
        }
61
62
        return $loader;
63
    }
64
}
65