Total Complexity | 7 |
Total Lines | 84 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
18 | class SubnetIterator implements \Iterator |
||
19 | { |
||
20 | /** |
||
21 | * @var Subnet $subnet local reference to the subnet to iterate |
||
22 | */ |
||
23 | protected $subnet; |
||
24 | |||
25 | /** |
||
26 | * @var int $index internal pointer in the subnet |
||
27 | */ |
||
28 | protected $index; |
||
29 | |||
30 | |||
31 | /** |
||
32 | * Créates the iterator |
||
33 | * |
||
34 | * Initialize internal pointer to the first position of the Subnet |
||
35 | * |
||
36 | * @param Subnet $subnet |
||
37 | */ |
||
38 | 1 | public function __construct(Subnet $subnet) |
|
39 | { |
||
40 | 1 | $this->subnet = $subnet; |
|
41 | 1 | $this->rewind(); |
|
42 | 1 | } |
|
43 | |||
44 | /** |
||
45 | * Return an Address representing the current element of the Subnet |
||
46 | * |
||
47 | * Use the ArrayAccess interface of the subnet. |
||
48 | * |
||
49 | * @return \mracine\IPTools\IPv4\Address |
||
50 | */ |
||
51 | 1 | public function current() |
|
52 | { |
||
53 | 1 | return $this->subnet[$this->index]; |
|
54 | } |
||
55 | |||
56 | /** |
||
57 | * Return the key of the current element |
||
58 | * |
||
59 | * @return int |
||
60 | */ |
||
61 | 1 | public function key() |
|
62 | { |
||
63 | 1 | return $this->index; |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * Move the internal pointer to the next element |
||
68 | * |
||
69 | * @return void |
||
70 | */ |
||
71 | 1 | public function next() |
|
72 | { |
||
73 | 1 | $this->index++; |
|
74 | 1 | } |
|
75 | |||
76 | /** |
||
77 | * Move the internal pointer to the first element |
||
78 | * |
||
79 | * @return void |
||
80 | */ |
||
81 | 1 | public function rewind() |
|
82 | { |
||
83 | 1 | $this->index = 0; |
|
84 | 1 | } |
|
85 | |||
86 | /** |
||
87 | * Tells if the internal pointer designs a valid element |
||
88 | * |
||
89 | * @return bool |
||
90 | */ |
||
91 | 1 | public function valid() |
|
102 | } |
||
103 | } |
||
104 | |||
105 | |||
106 |