RouteCollection::all()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.125

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 4
cp 0.5
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1.125
1
<?php declare(strict_types = 1);
2
3
namespace Venta\Routing;
4
5
use Venta\Contracts\Routing\Route as RouteContract;
6
use Venta\Contracts\Routing\RouteCollection as RouteCollectionContract;
7
use Venta\Contracts\Routing\RouteGroup as RouteGroupContract;
8
9
/**
10
 * Class RouteCollection
11
 *
12
 * @package Venta\Routing
13
 */
14
class RouteCollection implements RouteCollectionContract
15
{
16
17
    /**
18
     * @var RouteContract[]
19
     */
20
    private $routes = [];
21
22
    /**
23
     * @inheritDoc
24
     */
25 1
    public function addGroup(RouteGroupContract $group): RouteCollectionContract
26
    {
27 1
        foreach ($group->all() as $route) {
28 1
            $this->addRoute($route);
29
        }
30
31 1
        return $this;
32
    }
33
34
    /**
35
     * @inheritDoc
36
     */
37 7
    public function addRoute(RouteContract $route): RouteCollectionContract
38
    {
39 7
        $this->routes[] = $route;
40
41 7
        return $this;
42
    }
43
44
    /**
45
     * @inheritDoc
46
     */
47 6
    public function all(): array
48
    {
49 6
        return $this->routes;
50
    }
51
52
    /**
53
     * @inheritDoc
54
     */
55
    public function findByName(string $routeName)
56
    {
57
        foreach ($this->routes as $route) {
58
            if ($route->name() === $routeName) {
59
                return $route;
60
            }
61
        }
62
    }
63
64
}