ParseExpertConfig   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 15 4
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