RouteContainer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 31
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A getRoutes() 0 13 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