Completed
Push — master ( f72a4b...188ca1 )
by Pavel
04:06
created

Loader   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 57.14%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 53
ccs 8
cts 14
cp 0.5714
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A import() 0 4 1
A getResolver() 0 4 1
A setResolver() 0 4 1
A resolve() 0 14 4
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: batanov.pavel
5
 * Date: 16.02.2016
6
 * Time: 9:20
7
 */
8
9
namespace Bankiru\Api\Rpc\Routing\Loader;
10
11
12
use Bankiru\Api\Rpc\Routing\LoaderInterface;
13
use Bankiru\Api\Rpc\Routing\LoaderResolverInterface;
14
15
abstract class Loader implements LoaderInterface
16
{
17
    /** @var  LoaderResolverInterface */
18
    private $resolver;
19
20
    /**
21
     * Imports a resource.
22
     *
23
     * @param mixed       $resource A resource
24
     * @param string|null $type     The resource type or null if unknown
25
     *
26
     * @return mixed
27
     */
28
    public function import($resource, $type = null)
29
    {
30
        return $this->resolve($resource, $type)->load($resource, $type);
31
    }
32
33
    /**
34
     * Finds a loader able to load an imported resource.
35
     *
36
     * @param mixed       $resource A resource
37
     * @param string|null $type     The resource type or null if unknown
38
     *
39
     * @return LoaderInterface A LoaderInterface instance
40
     */
41 8
    public function resolve($resource, $type = null)
42
    {
43 8
        if ($this->supports($resource, $type)) {
44
            return $this;
45
        }
46
47 8
        $loader = null === $this->resolver ? false : $this->resolver->resolve($resource, $type);
48
49 8
        if (false === $loader) {
50
            throw new \OutOfBoundsException($resource);
51
        }
52
53 8
        return $loader;
54
    }
55
56
    /** {@inheritdoc} */
57
    public function getResolver()
58
    {
59
        return $this->resolver;
60
    }
61
62
    /** {@inheritdoc} */
63 8
    public function setResolver($resolver)
64
    {
65 8
        $this->resolver = $resolver;
66 8
    }
67
}
68