INIConfDriver::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
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