JsonConsoleConfigFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 16
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A decode() 0 11 3
1
<?php
2
3
/**
4
 * This file is part of PhpUnitGen.
5
 *
6
 * (c) 2017-2018 Paul Thébaud <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace PhpUnitGen\Configuration;
13
14
use PhpUnitGen\Exception\InvalidConfigException;
15
use PhpUnitGen\Exception\JsonException;
16
use PhpUnitGen\Util\Json;
17
18
/**
19
 * Class JsonConsoleConfigFactory.
20
 *
21
 * @author     Paul Thébaud <[email protected]>.
22
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
23
 * @license    https://opensource.org/licenses/MIT The MIT license.
24
 * @link       https://github.com/paul-thebaud/phpunit-generator
25
 * @since      Class available since Release 2.0.0.
26
 */
27
class JsonConsoleConfigFactory extends AbstractConsoleConfigFactory
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32
    protected function decode(string $configPath): array
33
    {
34
        try {
35
            $configArray = Json::decode(file_get_contents($configPath));
36
        } catch (JsonException $exception) {
37
            throw new InvalidConfigException('Unable to parse JSON config');
38
        }
39
        if (! is_array($configArray)) {
40
            throw new InvalidConfigException('Invalid JSON config');
41
        }
42
        return $configArray;
43
    }
44
}
45