JsonFileLoader   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 20
rs 10
c 1
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 7 2
A supports() 0 3 4
1
<?php
2
3
/*
4
 * This file is part of the awurth/config package.
5
 *
6
 * (c) Alexis Wurth <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace AWurth\Config\Loader;
13
14
use Symfony\Component\Config\Loader\Loader;
15
use Symfony\Component\Filesystem\Exception\FileNotFoundException;
16
17
/**
18
 * JSON File Loader.
19
 *
20
 * @author Alexis Wurth <[email protected]>
21
 */
22
class JsonFileLoader extends Loader
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function load($file, $type = null)
28
    {
29
        if (!file_exists($file)) {
30
            throw new FileNotFoundException(sprintf('File "%s" not found.', $file));
31
        }
32
33
        return json_decode(file_get_contents($file), true);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function supports($resource, $type = null)
40
    {
41
        return is_string($resource) && 'json' === pathinfo($resource, PATHINFO_EXTENSION) && (!$type || 'json' === $type);
42
    }
43
}
44