RouteContainer::getRoutes()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 4
nop 1
crap 4
1
<?php
2
3
namespace Kelemen\ApiNette\Route;
4
5
class RouteContainer
6
{
7
    /** @var array */
8
    private $routes = [];
9
10
    /**
11
     * @param Route $route
12
     */
13 38
    public function add(Route $route)
14
    {
15 38
        $this->routes[$route->getMethod()][] = $route;
16 38
    }
17
18
    /**
19
     * @param string|null $method
20
     * @return array
21
     */
22 38
    public function getRoutes($method = null)
23
    {
24 38
        if ($method !== null) {
25 38
            $method = strtolower($method);
26 38
            return isset($this->routes[$method]) ? $this->routes[$method] : [];
27
        }
28
29 2
        $routes = [];
30 2
        foreach ($this->routes as $routesByMethod) {
31 2
            $routes = array_merge($routes, $routesByMethod);
32 1
        }
33 2
        return $routes;
34
    }
35
}
36