Completed
Pull Request — master (#303)
by Atlas
02:57
created

ConfigFileReaderIni   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A read() 0 12 3
1
<?php
2
3
namespace Hal\Application\Config\File;
4
5
use Hal\Application\Config\Config;
6
7
class ConfigFileReaderIni implements ConfigFileReaderInterface
8
{
9
    /**
10
     * @var string
11
     */
12
    private $filename;
13
14
    /**
15
     * ConfigFileReaderIni constructor.
16
     *
17
     * @param string $filename
18
     */
19
    public function __construct($filename)
20
    {
21
        $this->filename = $filename;
22
    }
23
24
    /**
25
     * @param Config $config
26
     *
27
     * @return void
28
     */
29
    public function read(Config $config)
30
    {
31
        $options = parse_ini_file($this->filename);
32
33
        if (false === $options) {
34
            throw new \InvalidArgumentException("Cannot parse configuration file '{$this->filename}'");
35
        }
36
37
        foreach ($options as $name => $value) {
38
            $config->set($name, $value);
39
        }
40
    }
41
}
42