ChainedLoader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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