Passed
Push — master ( 8d13e1...d29b77 )
by Christian
01:52
created

YamlConfigProvider::readConfiguration()   B

Complexity

Conditions 7
Paths 64

Size

Total Lines 34
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 7

Importance

Changes 0
Metric Value
cc 7
eloc 17
nc 64
nop 0
dl 0
loc 34
ccs 17
cts 17
cp 1
crap 7
rs 8.8333
c 0
b 0
f 0
1
<?php
2
3
namespace Scheb\Tombstone\Analyzer\Config;
4
5
use Scheb\Tombstone\Analyzer\PathTools;
6
use Symfony\Component\Yaml\Yaml;
7
8
class YamlConfigProvider implements ConfigProviderInterface
9
{
10
    /**
11
     * @var string
12
     */
13
    private $configFile;
14
15 2
    public function __construct(string $configFile)
16
    {
17 2
        $this->configFile = $configFile;
18 2
    }
19
20 2
    public function readConfiguration(): array
21
    {
22 2
        $config = Yaml::parseFile($this->configFile);
23
24
        // Make all paths relative to config file path
25 2
        $configFileDir = dirname(realpath($this->configFile));
26
27 2
        if (isset($config['rootDir'])) {
28 1
            $config['rootDir'] = PathTools::makePathAbsolute($config['rootDir'], $configFileDir);
29
        }
30
31 2
        if (isset($config['source']['directories'])) {
32
            $config['source']['directories'] = array_map(function (string $directory) use ($configFileDir): string {
33 2
                return PathTools::makePathAbsolute($directory, $configFileDir);
34 2
            }, $config['source']['directories']);
35
        }
36
37 2
        if (isset($config['logs']['directory'])) {
38 2
            $config['logs']['directory'] = PathTools::makePathAbsolute($config['logs']['directory'], $configFileDir);
39
        }
40
41 2
        if (isset($config['logs']['custom']['file'])) {
42 1
            $config['logs']['custom']['file'] = PathTools::makePathAbsolute($config['logs']['custom']['file'], $configFileDir);
43
        }
44
45 2
        if (isset($config['report']['php'])) {
46 1
            $config['report']['php'] = PathTools::makePathAbsolute($config['report']['php'], $configFileDir);
47
        }
48
49 2
        if (isset($config['report']['html'])) {
50 1
            $config['report']['html'] = PathTools::makePathAbsolute($config['report']['html'], $configFileDir);
51
        }
52
53 2
        return $config;
54
    }
55
}
56