Completed
Push — develop ( 67e161...8b0772 )
by Paul
05:50
created

YamlConsoleConfigFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A invoke() 0 12 2
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 implements ConsoleConfigFactoryInterface
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function invoke(string $configPath): ConsoleConfigInterface
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
34
        return new ConsoleConfig($configArray);
35
    }
36
}
37