Router   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A addRoute() 0 4 1
A addRoutes() 0 6 2
A getRoutes() 0 4 1
route() 0 1 ?
1
<?php
2
3
namespace Air\Routing\Router;
4
5
use Air\Routing\Route\RouteInterface;
6
use Air\Routing\ResolvedRequest\ResolvedRequestInterface;
7
use Air\HTTP\Request\RequestInterface;
8
9
abstract class Router implements RouterInterface
10
{
11
    /**
12
     * @var array $routes An array of routes.
13
     */
14
    protected $routes;
15
16
17
    /**
18
     * @var string $cachePath A file path to cache routes in.
19
     */
20
    protected $cachePath;
21
22
23
    /**
24
     * @param array $routes An array of routes.
25
     * @param string $cachePath A file path to cache routes in.
26
     */
27
    public function __construct(array $routes, $cachePath = null)
28
    {
29
        $this->routes = $routes;
30
        $this->cachePath = $cachePath;
31
    }
32
33
34
    /**
35
     * @param RouteInterface $route A route.
36
     */
37
    public function addRoute(RouteInterface $route)
38
    {
39
        $this->routes[] = $route;
40
    }
41
42
43
    /**
44
     * @param array $routes An array of routes.
45
     */
46
    public function addRoutes(array $routes)
47
    {
48
        foreach ($routes as $route) {
49
            $this->addRoute($route);
50
        }
51
    }
52
53
54
    /**
55
     * @return array An array of routes.
56
     */
57
    public function getRoutes()
58
    {
59
        return $this->routes;
60
    }
61
62
63
    /**
64
     * Route a request.
65
     *
66
     * @param RequestInterface $request A request.
67
     * @return ResolvedRequestInterface A resolved request.
68
     */
69
    abstract public function route(RequestInterface $request);
70
}
71