ChainedLoader   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
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\JsonReference\Loader;
4
5
use League\JsonReference\LoaderInterface;
6
use League\JsonReference\SchemaLoadingException;
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
final class ChainedLoader implements LoaderInterface
14
{
15
    /**
16
     * @var LoaderInterface
17
     */
18
    private $firstLoader;
19
20
    /**
21
     * @var LoaderInterface
22
     */
23
    private $secondLoader;
24
25
    /**
26
     * @param \League\JsonReference\LoaderInterface $firstLoader
27
     * @param \League\JsonReference\LoaderInterface $secondLoader
28
     */
29 2
    public function __construct(LoaderInterface $firstLoader, LoaderInterface $secondLoader)
30
    {
31 2
        $this->firstLoader  = $firstLoader;
32 2
        $this->secondLoader = $secondLoader;
33 2
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 2
    public function load($path)
39
    {
40
        try {
41 2
            return $this->firstLoader->load($path);
42 2
        } catch (SchemaLoadingException $e) {
43 2
            return $this->secondLoader->load($path);
44
        }
45
    }
46
}
47