Test Failed
Pull Request — master (#32)
by Anatoly
04:53
created

RouteCollection::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 1
crap 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 Psr\Http\Server\MiddlewareInterface;
18
use Psr\Http\Server\RequestHandlerInterface;
19
use ArrayIterator;
20
21
/**
22
 * Import functions
23
 */
24
use function count;
25
26
/**
27
 * RouteCollection
28
 */
29
class RouteCollection implements RouteCollectionInterface
30
{
31
32
    /**
33
     * The collection routes
34
     *
35 24
     * @var RouteInterface[]
36
     */
37 24
    private $routes;
38
39 24
    /**
40
     * Constructor of the class
41
     *
42
     * @param RouteInterface ...$routes
43
     */
44
    public function __construct(RouteInterface ...$routes)
45 25
    {
46
        $this->routes = $routes;
47 25
    }
48
49
    /**
50
     * {@inheritDoc}
51
     */
52
    public function add(RouteInterface ...$routes) : void
53 21
    {
54
        foreach ($routes as $route) {
55 21
            $this->routes[] = $route;
56
        }
57 21
    }
58
59 21
    /**
60
     * {@inheritDoc}
61
     */
62
    public function all() : array
63
    {
64
        return $this->routes;
65 2
    }
66
67 2
    /**
68
     * Gets the number of routes in the collection
69 2
     *
70
     * @return int
71
     */
72
    public function count()
73
    {
74
        return count($this->routes);
75 11
    }
76
77 11
    /**
78
     * Gets an external iterator
79 11
     *
80
     * @return ArrayIterator
81
     */
82
    public function getIterator()
83
    {
84
        return new ArrayIterator($this->routes);
85 2
    }
86
}
87