Completed
Pull Request — master (#19)
by Andreas
09:05 queued 06:10
created

YAMLFileReader   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A read() 0 12 2
1
<?php
2
3
namespace TomPHP\ContainerConfigurator\FileReader;
4
5
use Assert\Assertion;
6
use Symfony\Component\Yaml;
7
use TomPHP\ContainerConfigurator\Exception\InvalidConfigException;
8
use TomPHP\ContainerConfigurator\Exception\MissingDependencyException;
9
10
final class YAMLFileReader implements FileReader
11
{
12
    public function __construct()
13
    {
14
        if (!class_exists(Yaml\Yaml::class)) {
15
            throw MissingDependencyException::fromPackageName('symfony/yaml');
16
        }
17
    }
18
19
    public function read($filename)
20
    {
21
        Assertion::file($filename);
22
23
        try {
24
            $config = Yaml\Yaml::parse(file_get_contents($filename));
25
        } catch (Yaml\Exception\ParseException $exception) {
26
            throw InvalidConfigException::fromYAMLFileError($filename, $exception->getMessage());
27
        }
28
29
        return $config;
30
    }
31
}
32