Passed
Push — master ( b202e3...14e011 )
by Divine Niiquaye
02:35 queued 13s
created

RouteCollection::__construct()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Flight Routing.
7
 *
8
 * PHP version 7.1 and above required
9
 *
10
 * @author    Divine Niiquaye Ibok <[email protected]>
11
 * @copyright 2019 Biurad Group (https://biurad.com/)
12
 * @license   https://opensource.org/licenses/BSD-3-Clause License
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 */
17
18
namespace Flight\Routing;
19
20
use ArrayIterator;
21
use CachingIterator;
22
use Countable;
23
use Flight\Routing\Interfaces\RouteCollectionInterface;
24
use Flight\Routing\Interfaces\RouteInterface;
25
26
/**
27
 * {@inheritdoc}
28
 */
29
class RouteCollection implements RouteCollectionInterface, Countable
30
{
31
    /**
32
     * The collection routes
33
     *
34
     * @var RouteInterface[]
35
     */
36
    private $routes;
37
38
    /**
39
     * Constructor of the class
40
     *
41
     * @param RouteInterface ...$routes
42
     */
43 25
    public function __construct(RouteInterface ...$routes)
44
    {
45 25
        $this->routes = $routes;
46 25
    }
47
48
    /**
49
     * {@inheritDoc}
50
     */
51 22
    public function add(RouteInterface ...$routes): void
52
    {
53 22
        foreach ($routes as $route) {
54 22
            $this->routes[] = $route;
55
        }
56 22
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 3
    public function count(): int
62
    {
63 3
        return count($this->routes);
64
    }
65
66
    /**
67
     * Gets all routes from the collection
68
     *
69
     * {@inheritDoc}
70
     */
71 5
    public function getIterator()
72
    {
73 5
        return new CachingIterator(new ArrayIterator($this->routes), CachingIterator::FULL_CACHE);
74
    }
75
}
76