ParseExpertConfig::parse()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.2
cc 4
eloc 8
nc 4
nop 1
1
<?php
2
namespace Metfan\RabbitSetup\Parser;
3
4
use Metfan\RabbitSetup\Configuration\ConfigExpertConfiguration;
5
use Symfony\Component\Config\Definition\Processor;
6
use Symfony\Component\Yaml\Yaml;
7
8
9
/**
10
 * Read Yaml config file and use Expert configuration to parse it
11
 *
12
 * @author Ulrich
13
 * @package Metfan\RabbitSetup\Manager\Command
14
 */
15
class ParseExpertConfig
16
{
17
    /**
18
     * @param $configFile
19
     * @return array
20
     */
21
    public function parse($configFile)
22
    {
23
        if ('/' !== substr($configFile, 0, 1)) {
24
            $configFile = ROOT_PATH.'/'.$configFile;
25
        }
26
27
        if (!is_file($configFile) || !is_readable($configFile)) {
28
            throw new \InvalidArgumentException(sprintf('Le fichier de config est inutilisable: %s', $configFile));
29
        }
30
31
        $configs = Yaml::parse(file_get_contents($configFile));
32
33
        $processor = new Processor();
34
        return $processor->processConfiguration(new ConfigExpertConfiguration(), $configs);
35
    }
36
}
37