Completed
Push — master ( 5ddc50...8d892a )
by John
02:13
created

INIConfiguration::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
namespace LunixREST\Configuration;
3
4
use LunixREST\Configuration\Exceptions\INIParseException;
5
6
/**
7
 * Configuration that reads in an ini file
8
 * Class INIConfiguration
9
 * @package LunixREST\Configuration
10
 */
11
class INIConfiguration implements Configuration
12
{
13
    /**
14
     * @var
15
     */
16
    protected $config;
17
18
    /**
19
     * @param string $filename
20
     * @throws INIParseException
21
     */
22 8
    public function __construct($filename)
23
    {
24 8
        $this->config = parse_ini_file($filename, true);
25
26 8
        if ($this->config === false) {
27 1
            throw new INIParseException('Could not parse: ' . $filename, true);
28
        }
29 7
    }
30
31
    /**
32
     * @param $key
33
     * @param $namespace
34
     * @return mixed
35
     */
36 3
    public function get($key, $namespace)
37
    {
38 3
        return $this->config[$namespace][$key] ?? null;
39
    }
40
41
    /**
42
     * @param $key
43
     * @param $namespace
44
     * @return bool
45
     */
46 3
    public function has($key, $namespace): bool
47
    {
48 3
        return isset($this->config[$namespace]) && isset($this->config[$namespace][$key]);
49
    }
50
}
51