Router::addRoutes()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4286
cc 2
eloc 3
nc 2
nop 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