Passed
Push — master ( 21057b...383a4e )
by Alexander
01:22
created

Group::getItems()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Yiisoft\Router;
4
5
use Psr\Http\Server\MiddlewareInterface;
6
use Yiisoft\Router\Middleware\Callback;
7
8
class Group implements RouteCollectorInterface
9
{
10
    protected $items = [];
11
    protected $prefix;
12
    protected $middlewares = [];
13
14 3
    public function __construct(string $prefix = null, callable $callback = null)
15
    {
16 3
        $this->prefix = $prefix;
17
18 3
        if ($callback !== null) {
19 1
            $callback($this);
20
        }
21
    }
22
23 2
    final public function addRoute(Route $route): void
24
    {
25 2
        $this->items[] = $route;
26
    }
27
28 1
    final public function addGroup(string $prefix, callable $callback): void
29
    {
30 1
        $this->items[] = new Group($prefix, $callback);
31
    }
32
33 2
    final public function addMiddleware($middleware): self
34
    {
35 2
        if (\is_callable($middleware)) {
36
            $middleware = new Callback($middleware);
37
        }
38
39 2
        if (!$middleware instanceof MiddlewareInterface) {
40
            throw new \InvalidArgumentException('Parameter should be either a PSR middleware or a callable.');
41
        }
42
43 2
        $this->middlewares[] = $middleware;
44
45 2
        return $this;
46
    }
47
48 2
    final public function getItems(): array
49
    {
50 2
        return $this->items;
51
    }
52
53 1
    final public function getPrefix(): ?string
54
    {
55 1
        return $this->prefix;
56
    }
57
58 2
    final public function getMiddlewares(): array
59
    {
60 2
        return $this->middlewares;
61
    }
62
}
63