Completed
Push — master ( 5927eb...1e13db )
by
unknown
04:04
created

FileGetContentsWebLoader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 92.31%
Metric Value
dl 0
loc 34
ccs 12
cts 13
cp 0.9231
rs 10
wmc 3
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A load() 0 15 2
1
<?php
2
3
namespace League\JsonGuard\Loaders;
4
5
use League\JsonGuard;
6
use League\JsonGuard\Exceptions\SchemaLoadingException;
7
use League\JsonGuard\Loader;
8
9
class FileGetContentsWebLoader implements Loader
10
{
11
    /**
12
     * @var string
13
     */
14
    private $prefix;
15
16
    /**
17
     * @param string $prefix
18
     */
19 4
    public function __construct($prefix)
20
    {
21 4
        $this->prefix = $prefix;
22 4
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 4
    public function load($path)
28
    {
29 4
        $uri = $this->prefix . $path;
30 4
        set_error_handler(function () use ($uri) {
31 2
            throw new SchemaLoadingException($uri);
32 4
        });
33 4
        $response = file_get_contents($uri);
34 2
        restore_error_handler();
35
36 2
        if (!$response) {
37
            throw SchemaLoadingException::create($uri);
38
        }
39
40 2
        return JsonGuard\json_decode($response);
41
    }
42
}
43