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

ChainableLoader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A load() 0 8 2
1
<?php
2
3
namespace League\JsonGuard\Loaders;
4
5
use League\JsonGuard\Exceptions\SchemaLoadingException;
6
use League\JsonGuard\Loader;
7
8
/**
9
 * This loader takes two other loaders as constructor parameters, and will
10
 * attempt to load from the first loader before deferring to the second loader.
11
 * This is useful when you would like to use multiple loaders for the same prefix.
12
 */
13
class ChainableLoader implements Loader
14
{
15
    /**
16
     * @var Loader
17
     */
18
    private $firstLoader;
19
20
    /**
21
     * @var Loader
22
     */
23
    private $secondLoader;
24
25
    /**
26
     * @param \League\JsonGuard\Loader $firstLoader
27
     * @param \League\JsonGuard\Loader $secondLoader
28
     */
29 62
    public function __construct(Loader $firstLoader, Loader $secondLoader)
30
    {
31 62
        $this->firstLoader  = $firstLoader;
32 62
        $this->secondLoader = $secondLoader;
33 62
    }
34
35
    /**
36
     * Load the json schema from the given path.
37
     *
38
     * @param string $path The path to load, without the protocol.
39
     *
40
     * @return object The object resulting from a json_decode of the loaded path.
41
     */
42 8
    public function load($path)
43
    {
44
        try {
45 8
            return $this->firstLoader->load($path);
46 4
        } catch (SchemaLoadingException $e) {
47 4
            return $this->secondLoader->load($path);
48
        }
49
    }
50
}
51