RouterCollection::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Xervice\Service\Route;
6
7
8
class RouterCollection implements \Iterator, \Countable
9
{
10
    /**
11
     * @var \Xervice\Service\Route\RouteInterface[]
12
     */
13
    private $collection;
14
15
    /**
16
     * @var int
17
     */
18
    private $position;
19
20
    /**
21
     * RouterCollection constructor.
22
     *
23
     * @param \Xervice\Service\Route\RouteInterface[] $collection
24
     */
25
    public function __construct(array $collection)
26
    {
27
        foreach ($collection as $route) {
28
            $this->add($route);
29
        }
30
    }
31
32
    /**
33
     * @param \Xervice\Service\Route\RouteInterface $route
34
     */
35
    public function add(RouteInterface $route)
36
    {
37
        $this->collection[] = $route;
38
    }
39
40
    /**
41
     * @return \Xervice\Service\Route\RouteInterface
42
     */
43
    public function current()
44
    {
45
        return $this->collection[$this->position];
46
    }
47
48
    public function next()
49
    {
50
        $this->position++;
51
    }
52
53
    /**
54
     * @return int
55
     */
56
    public function key()
57
    {
58
        return $this->position;
59
    }
60
61
    /**
62
     * @return bool
63
     */
64
    public function valid()
65
    {
66
        return isset($this->collection[$this->position]);
67
    }
68
69
    public function rewind()
70
    {
71
        $this->position = 0;
72
    }
73
74
    /**
75
     * @return int
76
     */
77
    public function count()
78
    {
79
        return \count($this->collection);
80
    }
81
82
83
}