Passed
Push — master ( 196a37...9e483f )
by Pol
05:12
created

JsonConfigLoader::load()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3.0052

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 3
nop 1
dl 0
loc 24
ccs 11
cts 12
cp 0.9167
crap 3.0052
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace PhpTaskman\Core\Config\Loader;
6
7
use Consolidation\Config\Loader\ConfigLoader;
8
9
class JsonConfigLoader extends ConfigLoader
10
{
11 1
    public function load($path)
12
    {
13 1
        $this->setSourceName($path);
14
15
        // We silently skip any nonexistent config files, so that
16
        // clients may simply `load` all of their candidates.
17 1
        if (!\file_exists($path)) {
18 1
            $this->config = [];
19
20 1
            return $this;
21
        }
22
23 1
        $content = \file_get_contents($path);
24
25 1
        if (false === $content) {
26
            return $this;
27
        }
28
29 1
        $this->config = (array) \json_decode(
30 1
            $content,
31 1
            true
32
        );
33
34 1
        return $this;
35
    }
36
}
37