Passed
Pull Request — master (#34)
by Anatoly
02:04
created

RouteCollection   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 2
A count() 0 3 1
A __construct() 0 3 1
A all() 0 3 1
A getIterator() 0 3 1
1
<?php declare(strict_types=1);
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Fenric <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Fenric
8
 * @license https://github.com/sunrise-php/http-router/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-router
10
 */
11
12
namespace Sunrise\Http\Router;
13
14
/**
15
 * Import classes
16
 */
17
use ArrayIterator;
18
19
/**
20
 * Import functions
21
 */
22
use function count;
23
24
/**
25
 * RouteCollection
26
 */
27
class RouteCollection implements RouteCollectionInterface
28
{
29
30
    /**
31
     * The collection routes
32
     *
33
     * @var RouteInterface[]
34
     */
35
    private $routes;
36
37
    /**
38
     * Constructor of the class
39
     *
40
     * @param RouteInterface ...$routes
41
     */
42 47
    public function __construct(RouteInterface ...$routes)
43
    {
44 47
        $this->routes = $routes;
45 47
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50 35
    public function add(RouteInterface ...$routes) : void
51
    {
52 35
        foreach ($routes as $route) {
53 35
            $this->routes[] = $route;
54
        }
55 35
    }
56
57
    /**
58
     * {@inheritDoc}
59
     */
60 13
    public function all() : array
61
    {
62 13
        return $this->routes;
63
    }
64
65
    /**
66
     * Gets the number of routes in the collection
67
     *
68
     * @return int
69
     */
70 3
    public function count()
71
    {
72 3
        return count($this->routes);
73
    }
74
75
    /**
76
     * Gets an external iterator
77
     *
78
     * @return ArrayIterator
79
     */
80 3
    public function getIterator()
81
    {
82 3
        return new ArrayIterator($this->routes);
83
    }
84
}
85