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

Router   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 78.56%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 5
c 2
b 1
f 0
lcom 0
cbo 3
dl 0
loc 42
ccs 11
cts 14
cp 0.7856
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 4
A getCollection() 0 4 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: batanov.pavel
5
 * Date: 16.02.2016
6
 * Time: 10:25
7
 */
8
9
namespace Bankiru\Api\Rpc\Routing;
10
11
class Router
12
{
13
    /** @var  MethodCollection */
14
    private $collection;
15
16
    /**
17
     * Router constructor.
18
     *
19
     * @param LoaderResolverInterface $resolver
20
     * @param array                   $resources
21
     * @param MethodCollection|null   $collection
22
     *
23
     * @throws \RuntimeException
24
     */
25 8
    public function __construct(
26
        LoaderResolverInterface $resolver,
27
        array $resources = [],
28
        MethodCollection $collection = null)
29
    {
30 8
        $this->collection = $collection;
31
32 8
        if (null === $this->collection) {
33
            $this->collection = new MethodCollection();
34
        }
35
36 8
        foreach ($resources as $resource) {
37 8
            $loader = $resolver->resolve($resource);
38 8
            if (false === $loader) {
39
                throw new \RuntimeException(sprintf('Could not resolve loader for resource "%s"', $resource));
40
            }
41 8
            $this->collection->addCollection($loader->load($resource));
42 8
        }
43 8
    }
44
45
    /**
46
     * @return MethodCollection
47
     */
48 8
    public function getCollection()
49
    {
50 8
        return $this->collection;
51
    }
52
}
53