Completed
Push — develop ( 8b0772...a0b2b6 )
by Paul
04:54
created

YamlConsoleConfigFactory::invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace PhpUnitGen\Configuration;
4
5
use PhpUnitGen\Exception\InvalidConfigException;
6
use Symfony\Component\Yaml\Exception\ParseException;
7
use Symfony\Component\Yaml\Yaml;
8
9
/**
10
 * Class YamlConsoleConfigFactory.
11
 *
12
 * @author     Paul Thébaud <[email protected]>.
13
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
14
 * @license    https://opensource.org/licenses/MIT The MIT license.
15
 * @link       https://github.com/paul-thebaud/phpunit-generator
16
 * @since      Class available since Release 2.0.0.
17
 */
18
class YamlConsoleConfigFactory extends AbstractConsoleConfigFactory
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    protected function decode(string $configPath): array
24
    {
25
        try {
26
            $configArray = Yaml::parse(file_get_contents($configPath));
27
        } catch (ParseException $exception) {
28
            throw new InvalidConfigException(sprintf(
29
                'Unable to parse YAML config: %s',
30
                $exception->getMessage()
31
            ));
32
        }
33
        return $configArray;
34
    }
35
}
36