Completed
Pull Request — master (#283)
by Enrico
04:27
created

ConfigurationLoader   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 57.14%

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 4
cts 7
cp 0.5714
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 4 2
A load() 0 10 2
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA;
7
8
use Symfony\Component\Config\Loader\FileLoader;
9
use Symfony\Component\Yaml\Yaml;
10
11
/**
12
 * Loads configuration from a YAML file
13
 */
14
class ConfigurationLoader extends FileLoader
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19 1
    public function load($resource, $type = null)
20
    {
21
        try {
22 1
            $this->locator->locate($resource);
23 1
        } catch (\InvalidArgumentException $e) {
24
            return [];
25
        }
26
27 1
        return Yaml::parse(file_get_contents($resource));
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function supports($resource, $type = null)
34
    {
35
        return is_string($resource) && 'yml' === pathinfo($resource, PATHINFO_EXTENSION);
36
    }
37
}
38