RouteCollection   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 37.5%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 51
ccs 9
cts 24
cp 0.375
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addGroup() 0 8 2
A addRoute() 0 6 1
A all() 0 4 1
A findByName() 0 8 3
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
}