Passed
Push — master ( 5303d6...4d5c22 )
by Alexis
04:40
created

JsonFileLoader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 5 1
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\FileLoader;
15
16
/**
17
 * JSON File Loader.
18
 *
19
 * @author Alexis Wurth <[email protected]>
20
 */
21
class JsonFileLoader extends FileLoader
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function load($file, $type = null)
27
    {
28
        $path = $this->locator->locate($file);
29
30
        return json_decode(file_get_contents($path), true);
0 ignored issues
show
Bug introduced by
It seems like $path can also be of type array; however, parameter $filename of file_get_contents() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
        return json_decode(file_get_contents(/** @scrutinizer ignore-type */ $path), true);
Loading history...
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function supports($resource, $type = null)
37
    {
38
        return is_string($resource) && 'json' === pathinfo($resource, PATHINFO_EXTENSION) && (!$type || 'json' === $type);
39
    }
40
}
41