INIConfDriver::parseConfigurationFile()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 3
c 2
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
cc 3
nc 4
nop 1
crap 3
1
<?php
2
3
namespace GeekLab\Conf\Driver;
4
5
final class INIConfDriver implements ConfDriverInterface
6
{
7
    private string $mainConfFile; // Path and file name of the top configuration file.
8
    private string $confLocation; // Path of the configuration files
9
10
    /**
11
     * INIConfDriver constructor.
12
     *
13
     * @param string $mainConfFile
14
     * @param string $confLocation
15
     */
16 2
    public function __construct(string $mainConfFile, string $confLocation)
17
    {
18 2
        $this->mainConfFile = $mainConfFile;
19 2
        $this->confLocation = $confLocation;
20
    }
21
22
    /**
23
     * Load and parse a configuration file and return an array.
24
     *
25
     * @param string | null $file If null, then load the main configuration file
26
     *
27
     * @return array
28
     */
29 2
    public function parseConfigurationFile(?string $file = null): array
30
    {
31 2
        $fileName = $file === null ? $this->mainConfFile : $this->confLocation . $file . '.ini';
32 2
        $parsed = parse_ini_file($fileName, $file !== null);
33
34 2
        return !empty($parsed) ? $parsed : [];
35
    }
36
}
37