INIConfig   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 6
c 1
b 0
f 0
dl 0
loc 23
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A parseFile() 0 7 3
1
<?php
2
declare(strict_types=1);
3
4
namespace SKien\Config;
5
6
/**
7
 * Class for config component getting data from INI file.
8
 * Lines begin with semikolon are ignored as comments.
9
 * The begin of a section have to be set in square brackets.
10
 * A section is active until next section begins or to the end of file.
11
 *
12
 * @package Config
13
 * @author Stefanius <[email protected]>
14
 * @copyright MIT License - see the LICENSE file for details
15
 */
16
class INIConfig extends AbstractConfig
17
{
18
    /**
19
     * The constructor expects an valid filename/path to the JSON file.
20
     * @param string $strConfigFile
21
     */
22
    public function __construct(string $strConfigFile)
23
    {
24
        $this->aConfig = $this->parseFile($strConfigFile);
25
    }
26
27
    /**
28
     * Parse the given file an add all settings to the internal configuration.
29
     * @param string $strConfigFile
30
     * @return array<mixed>
31
     */
32
    protected function parseFile(string $strConfigFile) : array
33
    {
34
        if (!file_exists($strConfigFile)) {
35
            trigger_error('Config File (' . $strConfigFile . ') does not exist!', E_USER_WARNING);
36
        }
37
        $aINI = parse_ini_file($strConfigFile, TRUE);
38
        return ($aINI !== false) ? $aINI : [];
39
    }
40
}
41