SubnetIterator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 40
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A rewind() 0 3 1
A key() 0 3 1
A valid() 0 3 1
A __construct() 0 4 1
A next() 0 3 1
A current() 0 3 1
1
<?php
2
3
namespace ColinODell\Ipv4;
4
5
/**
6
 * An object that implements a subnet iterator.
7
 */
8
class SubnetIterator implements \Iterator
9
{
10
    private $position = 0;
11
    private $low_dec;
12
    private $hi_dec;
13
14
    /**
15
     * SubnetIterator constructor.
16
     *
17
     * @param Subnet $subnet
18
     */
19 9
    public function __construct(Subnet $subnet)
20
    {
21 9
        $this->low_dec = ip2long($subnet->getFirstHostAddr());
22 9
        $this->hi_dec = ip2long($subnet->getLastHostAddr());
23 9
    }
24
25 6
    public function rewind()
26
    {
27 6
        $this->position = 0;
28 6
    }
29
30 9
    public function current()
31
    {
32 9
        return long2ip($this->low_dec + $this->position);
33
    }
34
35 3
    public function key()
36
    {
37 3
        return $this->position;
38
    }
39
40 9
    public function next()
41
    {
42 9
        $this->position++;
43 9
    }
44
45 6
    public function valid()
46
    {
47 6
        return ($this->low_dec + $this->position) <= $this->hi_dec;
48
    }
49
}
50