ChainLoader   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 10
dl 0
loc 25
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 13 3
A __construct() 0 3 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