FlatRouteCollection   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 59
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addRoute() 0 4 1
A getRoute() 0 8 2
A getRoutes() 0 11 2
A __construct() 0 7 2
1
<?php
2
/**
3
 * ZfDebugModule. WebUI and Console commands for debugging ZF2 apps.
4
 *
5
 * @license http://www.opensource.org/licenses/mit-license.html MIT License
6
 * @copyright 2016 Vítor Brandão <[email protected]>
7
 */
8
9
namespace Noiselabs\ZfDebugModule\Util\Routing;
10
11
class FlatRouteCollection implements RouteCollection
12
{
13
    /**
14
     * @var Route[]
15
     */
16
    private $routes;
17
18
    /**
19
     * RouteCollection constructor.
20
     *
21
     * @param array $routes
22
     */
23 16
    public function __construct(array $routes = [])
24
    {
25 16
        $this->routes = [];
26 16
        foreach ($routes as $route) {
27 4
            $this->addRoute($route);
28
        }
29 16
    }
30
31
    /**
32
     * @param Route $route
33
     */
34 14
    public function addRoute(Route $route)
35
    {
36 14
        $this->routes[$route->getName()] = $route;
37 14
    }
38
39
    /**
40
     * @param string $routeName
41
     *
42
     * @return Route|null
43
     */
44 5
    public function getRoute($routeName)
45
    {
46 5
        if (!isset($this->routes[$routeName])) {
47 1
            return;
48
        }
49
50 4
        return $this->routes[$routeName];
51
    }
52
53
    /**
54
     * @param bool $sort
55
     *
56
     * @return array|\Traversable
57
     */
58 7
    public function getRoutes($sort = true)
59
    {
60 7
        if (true === $sort) {
61 6
            $routes = $this->routes;
62 6
            ksort($routes, SORT_NATURAL);
63
64 6
            return $routes;
65
        }
66
67 1
        return $this->routes;
68
    }
69
}
70