Test Failed
Push — main ( bc775a...919c7e )
by Stefan
07:40
created

INIConfig::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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
 * #### History
13
 * - *2021-01-01*   initial version
14
 *
15
 * @package SKien/Config
16
 * @version 1.0.0
17
 * @author Stefanius <[email protected]>
18
 * @copyright MIT License - see the LICENSE file for details
19
 */
20
class INIConfig extends AbstractConfig
21
{
22
    /**
23
     * The constructor expects an valid filename/path to the JSON file.
24
     * @param string $strConfigFile
25
     */
26
    public function __construct(string $strConfigFile)
27
    {
28
        $this->aConfig = $this->parseFile($strConfigFile);
29
    }
30
    
31
    /**
32
     * Parse the given file an add all settings to the internal configuration. 
33
     * @param string $strConfigFile
34
     */
35
    protected function parseFile(string $strConfigFile) : array
36
    {
37
        if (!file_exists($strConfigFile)) {
38
            trigger_error('Config File (' . $strConfigFile . ') does not exist!', E_USER_WARNING);
39
        }
40
        $aINI = parse_ini_file($strConfigFile, TRUE);
41
        return $aINI;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $aINI could return the type false which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
42
    }
43
}
44