Completed
Push — master ( 72efb5...e53b1a )
by Vítor
02:42
created

FlatRouteCollection   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 6
c 2
b 0
f 2
lcom 1
cbo 1
dl 0
loc 53
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addRoute() 0 4 1
A getRoute() 0 8 2
A getRoutes() 0 8 2
1
<?php
2
/**
3
 * ZfDebugModule. Console commands and other utilities 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
    public function __construct(array $routes = [])
24
    {
25
        $this->routes = $routes;
26
    }
27
28
    /**
29
     * @param Route $route
30
     */
31
    public function addRoute(Route $route)
32
    {
33
        $this->routes[$route->getName()] = $route;
34
    }
35
36
    /**
37
     * @param string $routeName
38
     *
39
     * @return Route|null
40
     */
41
    public function getRoute($routeName)
42
    {
43
        if (!isset($this->routes[$routeName])) {
44
            return null;
45
        }
46
        
47
        return $this->routes[$routeName];
48
    }
49
50
    /**
51
     * @param bool $sort
52
     *
53
     * @return array|\Traversable
54
     */
55
    public function getRoutes($sort = true)
56
    {
57
        if (true === $sort) {
58
            ksort($this->routes, SORT_NATURAL);
59
        }
60
61
        return $this->routes;
62
    }
63
}
64