Completed
Push — master ( 055f1b...f72a4b )
by Pavel
52s
created

LoaderResolver   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 68.75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 53
ccs 11
cts 16
cp 0.6875
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A resolve() 0 10 3
A addLoader() 0 4 1
A getLoaders() 0 4 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: batanov.pavel
5
 * Date: 16.02.2016
6
 * Time: 8:49
7
 */
8
9
namespace Bankiru\Api\Rpc\Routing;
10
11
12
class LoaderResolver implements LoaderResolverInterface
13
{
14
    /**
15
     * @var LoaderInterface[] An array of LoaderInterface objects
16
     */
17
    private $loaders = array();
18
19
    /**
20
     * Constructor.
21
     *
22
     * @param LoaderInterface[] $loaders An array of loaders
23
     */
24 8
    public function __construct(array $loaders = array())
25
    {
26 8
        foreach ($loaders as $loader) {
27
            $this->addLoader($loader);
28 8
        }
29 8
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 8
    public function resolve($resource, $type = null)
35
    {
36 8
        foreach ($this->loaders as $loader) {
37 8
            if ($loader->supports($resource, $type)) {
38 8
                return $loader;
39
            }
40
        }
41
42
        return false;
43
    }
44
45
    /**
46
     * Adds a loader.
47
     *
48
     * @param LoaderInterface $loader A LoaderInterface instance
49
     */
50 8
    public function addLoader(LoaderInterface $loader)
51
    {
52 8
        $this->loaders[] = $loader;
53 8
    }
54
55
    /**
56
     * Returns the registered loaders.
57
     *
58
     * @return LoaderInterface[] An array of LoaderInterface instances
59
     */
60
    public function getLoaders()
61
    {
62
        return $this->loaders;
63
    }
64
}
65