Completed
Pull Request — master (#5)
by Pavel
04:05
created

Router   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 82.35%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 6
c 3
b 1
f 0
lcom 0
cbo 3
dl 0
loc 48
ccs 14
cts 17
cp 0.8235
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 25 5
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
     * @param array                   $context
24
     */
25 8
    public function __construct(
26
        LoaderResolverInterface $resolver,
27
        array $resources = [],
28
        MethodCollection $collection = null,
29
        array $context = []
30
    )
31
    {
32 8
        $this->collection = $collection;
33
34 8
        if (null === $this->collection) {
35
            $this->collection = new MethodCollection();
36
        }
37
38 8
        foreach ($resources as $resource) {
39 8
            $loader = $resolver->resolve($resource);
40 8
            if (false === $loader) {
41
                throw new \RuntimeException(sprintf('Could not resolve loader for resource "%s"', $resource));
42
            }
43 8
            $this->collection->addCollection($loader->load($resource));
44 8
        }
45
46 8
        foreach ($context as $item) {
47 8
            $this->collection->addContext($item);
48 8
        }
49 8
    }
50
51
    /**
52
     * @return MethodCollection
53
     */
54 8
    public function getCollection()
55
    {
56 8
        return $this->collection;
57
    }
58
}
59