Failed Conditions
Push — master ( c24b3a...b512e9 )
by Florent
14:42
created

DomainUriLoader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A load() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\Component\Core\Domain;
15
16
use League\JsonReference\SchemaLoadingException;
17
use League\JsonReference\LoaderInterface;
18
19
class DomainUriLoader implements LoaderInterface
20
{
21
    /**
22
     * @var string[]
23
     */
24
    private $mappings = [];
25
26
    /**
27
     * @param string $schema
28
     * @param string $filename
29
     */
30
    public function add(string $schema, string $filename)
31
    {
32
        $this->mappings[$schema] = $filename;
33
    }
34
35
    public function load($path)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
36
    {
37
        if (array_key_exists($path, $this->mappings)) {
38
            $content = file_get_contents($this->mappings[$path]);
39
40
            return json_decode($content);
41
        }
42
43
        throw SchemaLoadingException::notFound(sprintf('The schema "%s" is not supported.', $path));
44
    }
45
}
46