FileLoader::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace League\JsonReference\Loader;
4
5
use League\JsonReference\Decoder\JsonDecoder;
6
use League\JsonReference\DecoderInterface;
7
use League\JsonReference\LoaderInterface;
8
use League\JsonReference\SchemaLoadingException;
9
10
final class FileLoader implements LoaderInterface
11
{
12
    /**
13
     * @var DecoderInterface
14
     */
15
    private $jsonDecoder;
16
17
    /**
18
     * @param DecoderInterface $jsonDecoder
19
     */
20 62
    public function __construct(DecoderInterface $jsonDecoder = null)
21
    {
22 62
        $this->jsonDecoder = $jsonDecoder ?: new JsonDecoder();
23 62
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 38
    public function load($path)
29
    {
30 38
        $uri = 'file://' . $path;
31
        
32 38
        if (!file_exists($uri)) {
33 4
            throw SchemaLoadingException::notFound($uri);
34
        }
35
36 34
        return $this->jsonDecoder->decode(file_get_contents($uri));
37
    }
38
}
39