YAMLConfDriver   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
eloc 9
c 2
b 1
f 0
dl 0
loc 30
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A parseConfigurationFile() 0 6 2
1
<?php
2
3
namespace GeekLab\Conf\Driver;
4
5
use Symfony\Component\Yaml\Parser;
6
7
final class YAMLConfDriver implements ConfDriverInterface
8
{
9
    private string $mainConfFile; // Path and file name of the top configuration file.
10
    private string $confLocation; // Path of the configuration files.
11
12
    /**
13
     * YAMLConfDriver constructor.
14
     *
15
     * @param string $mainConfFile
16
     * @param string $confLocation
17
     */
18 2
    public function __construct(string $mainConfFile, string $confLocation)
19
    {
20 2
        $this->mainConfFile = $mainConfFile;
21 2
        $this->confLocation = $confLocation;
22
    }
23
24
    /**
25
     * Load and parse a configuration file and return an array.
26
     *
27
     * @param string | null $file If null, then load the main configuration file
28
     *
29
     * @return array
30
     */
31 2
    public function parseConfigurationFile(?string $file = null): array
32
    {
33 2
        return (array)(new Parser())->parseFile(
34 2
            $file === null
35 2
                ? $this->mainConfFile
36 2
                : $this->confLocation . $file . '.yaml'
37
        );
38
    }
39
}
40