Completed
Pull Request — master (#52)
by Tom
02:42
created

PHPFileReader::read()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
3
namespace TomPHP\ContainerConfigurator\FileReader;
4
5
use Assert\Assertion;
6
use TomPHP\ContainerConfigurator\Exception\InvalidConfigException;
7
8
final class PHPFileReader implements FileReader
9
{
10
    private $filename;
11
12
    public function read($filename)
13
    {
14
        Assertion::file($filename);
15
16
        $this->filename = $filename;
17
18
        $config = include $this->filename;
19
20
        $this->assertConfigIsValid($config);
21
22
        return $config;
23
    }
24
25
    private function assertConfigIsValid($config)
26
    {
27
        if (!is_array($config)) {
28
            throw InvalidConfigException::fromPHPFileError($this->filename);
29
        }
30
    }
31
}
32