Completed
Push — master ( dacaa0...701f1f )
by Vítor
02:08
created

FlatRouteCollection::addRoute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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 array
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 bool $sort
38
     *
39
     * @return array|\Traversable
40
     */
41
    public function getRoutes($sort = true)
42
    {
43
        if (true === $sort) {
44
            ksort($this->routes, SORT_NATURAL);
45
        }
46
47
        return $this->routes;
48
    }
49
}
50