Passed
Push — master ( abee1f...edc958 )
by Kirill
03:08
created

JsonLoader::loadFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Config\Loader;
13
14
use Spiral\Config\Exception\LoaderException;
15
16
final class JsonLoader implements FileLoaderInterface
17
{
18
    /**
19
     * @inheritdoc
20
     */
21
    public function loadFile(string $section, string $filename): array
22
    {
23
        $content = file_get_contents($filename);
24
        $data = json_decode($content, true);
25
26
        if (is_null($data)) {
27
            throw new LoaderException(json_last_error_msg(), json_last_error());
28
        }
29
30
        return $data;
31
    }
32
}
33