DispatcherProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 11
c 1
b 0
f 0
dl 0
loc 35
ccs 10
cts 10
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 18 2
1
<?php
2
3
namespace App\Zapheus;
4
5
use Zapheus\Container\WritableInterface;
6
use Zapheus\Provider\ProviderInterface;
7
use Zapheus\Routing\Dispatcher;
8
use Zapheus\Routing\Router;
9
use Zapheus\Routing\DispatcherInterface;
10
11
/**
12
 * Dispatcher Provider
13
 *
14
 * @package App
15
 * @author  Rougin Gutib <[email protected]>
16
 */
17
class DispatcherProvider implements ProviderInterface
18
{
19
    const DISPATCHER = 'Zapheus\Routing\DispatcherInterface';
20
21
    /**
22
     * An array of Zapheus\Routing\RouterInterface instances.
23
     *
24
     * @var string[]
25
     */
26
    protected $routers = array('App\Example\RouteCollection');
27
28
    /**
29
     * Registers the bindings in the container.
30
     *
31
     * @param  \Zapheus\Container\WritableInterface $container
32
     * @return \Zapheus\Container\ContainerInterface
33
     */
34 9
    public function register(WritableInterface $container)
35
    {
36 9
        $routes = array();
37
38 9
        foreach ((array) $this->routers as $router)
39
        {
40 9
            $item = $container->get((string) $router);
41
42 9
            $current = (array) $item->routes();
43
44 9
            $routes = array_merge($routes, $current);
45 3
        }
46
47 9
        $router = new Router((array) $routes);
48
49 9
        $dispatcher = new Dispatcher($router);
50
51 9
        return $container->set(self::DISPATCHER, $dispatcher);
52
    }
53
}
54