ChainLoader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of ocubom/twig-svg-extension
5
 *
6
 * © Oscar Cubo Medina <https://ocubom.github.io>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ocubom\Twig\Extension\Svg\Loader;
13
14
use Ocubom\Twig\Extension\Svg\Exception\LoaderException;
15
use Ocubom\Twig\Extension\Svg\Svg;
16
17
class ChainLoader implements LoaderInterface
18
{
19
    private iterable $loaders;
20
21
    /**
22
     * @param iterable<LoaderInterface> $loaders
23
     */
24 20
    public function __construct(iterable $loaders = null)
25
    {
26 20
        $this->loaders = $loaders ?? /* @scrutinizer ignore-type */ [];
27
    }
28
29 5
    public function resolve(string $ident, iterable $options = null): Svg
30
    {
31 5
        $errors = [];
32 5
        foreach ($this->loaders as $loader) {
33
            /* @var LoaderInterface $loader */
34
            try {
35 5
                return $loader->resolve($ident, $options);
36 4
            } catch (LoaderException $err) {
37 3
                $errors[] = $err;
38
            }
39
        }
40
41 1
        throw new LoaderException($ident, new \ReflectionClass(__CLASS__), null, 0, $errors);
42
    }
43
}
44