Passed
Pull Request — master (#115)
by Rustam
02:24
created

RouteCollector   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 59
ccs 16
cts 16
cp 1
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getItems() 0 3 1
A addGroup() 0 4 1
A getMiddlewareDefinitions() 0 3 1
A prependMiddleware() 0 4 1
A addRoute() 0 4 1
A middleware() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Router;
6
7
final class RouteCollector implements RouteCollectorInterface
8
{
9
    /**
10
     * @var Group[]|Route[]
11
     */
12
    private array $items = [];
13
    private array $middlewareDefinitions = [];
14
15 1
    public function addRoute(Route $route): RouteCollectorInterface
16
    {
17 1
        $this->items[] = $route;
18 1
        return $this;
19
    }
20
21 9
    public function addGroup(Group $group): RouteCollectorInterface
22
    {
23 9
        $this->items[] = $group;
24 9
        return $this;
25
    }
26
27
    /**
28
     * Appends a handler middleware definition that should be invoked for a matched route.
29
     * First added handler will be executed first.
30
     *
31
     * @param mixed $middlewareDefinition
32
     *
33
     * @return self
34
     */
35 1
    public function middleware($middlewareDefinition): RouteCollectorInterface
36
    {
37 1
        array_unshift($this->middlewareDefinitions, $middlewareDefinition);
38 1
        return $this;
39
    }
40
41
    /**
42
     * Prepends a handler middleware definition that should be invoked for a matched route.
43
     * First added handler will be executed last.
44
     *
45
     * @param mixed $middlewareDefinition
46
     *
47
     * @return self
48
     */
49 1
    public function prependMiddleware($middlewareDefinition): RouteCollectorInterface
50
    {
51 1
        $this->middlewareDefinitions[] = $middlewareDefinition;
52 1
        return $this;
53
    }
54
55
    /**
56
     * @return Group[]|Route[]
57
     */
58 10
    public function getItems(): array
59
    {
60 10
        return $this->items;
61
    }
62
63 9
    public function getMiddlewareDefinitions(): array
64
    {
65 9
        return $this->middlewareDefinitions;
66
    }
67
}
68