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

JsonConsoleConfigFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A invoke() 0 8 2
1
<?php
2
3
namespace PhpUnitGen\Configuration;
4
5
use PhpUnitGen\Exception\InvalidConfigException;
6
7
/**
8
 * Class JsonConsoleConfigFactory.
9
 *
10
 * @author     Paul Thébaud <[email protected]>.
11
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
12
 * @license    https://opensource.org/licenses/MIT The MIT license.
13
 * @link       https://github.com/paul-thebaud/phpunit-generator
14
 * @since      Class available since Release 2.0.0.
15
 */
16
class JsonConsoleConfigFactory implements ConsoleConfigFactoryInterface
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function invoke(string $configPath): ConsoleConfigInterface
22
    {
23
        $configArray = json_decode(file_get_contents($configPath), true);
24
        if (! is_array($configArray)) {
25
            throw new InvalidConfigException('Unable to parse JSON config');
26
        }
27
28
        return new ConsoleConfig($configArray);
29
    }
30
}
31