FileLoader   A
last analyzed

Coupling/Cohesion

Components 1
Dependencies 3

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A load() 0 10 2
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