JsonFileLoader::supports()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 1
c 1
b 0
f 0
nc 5
nop 2
dl 0
loc 3
rs 9.2
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