FileLoader   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 40
ccs 9
cts 11
cp 0.8182
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B load() 0 21 5
loadResource() 0 1 ?
1
<?php
2
3
namespace GalantomApi\Description;
4
5
use Symfony\Component\Config\Loader\FileLoader as BaseFileLoader;
6
7
/**
8
 * Class FileLoader
9
 * @package GalantomApi\Description
10
 */
11
abstract class FileLoader extends BaseFileLoader
12
{
13
14
    /**
15
     * Loads a resource.
16
     *
17
     * @param mixed $resource The resource
18
     * @param string|null $type The resource type or null if unknown
19
     *
20
     * @throws \Exception If something went wrong
21
     */
22 2
    public function load($resource, $type = null)
23
    {
24 2
        if (!stream_is_local($resource)) {
25
            throw new \Exception(sprintf('This is not a local file "%s".', $resource));
26
        }
27 2
        if (!file_exists($resource)) {
28
            throw new \Exception(sprintf('File "%s" not found.', $resource));
29
        }
30
31 2
        $configValues = $this->loadResource($resource);
32
33 2
        if (isset($configValues["imports"])) {
34 2
            foreach ($configValues["imports"] as $file) {
35 2
                $configValues = array_merge_recursive($configValues, $this->import($this->locator->locate($file)));
36
            }
37
        }
38
39 2
        unset($configValues["imports"]);
40
41 2
        return $configValues;
42
    }
43
44
    /**
45
     * @param $resource
46
     * @return array
47
     * @throws InvalidResourceException If stream content has an invalid format.
48
     */
49
    abstract protected function loadResource($resource);
50
}
51