Completed
Push — master ( ba922a...9c7654 )
by Milos
03:24
created

LineIterator::valid()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 0
1
<?php
2
3
namespace Cgi\Calc\Point;
4
5
use Cgi\Calc\Point;
6
7
class LineIterator implements \Iterator
8
{
9
    /** @var Point[] */
10
    private $points;
11
12
    /** @var int */
13
    private $index = 0;
14
15
    /**
16
     * @param Path $path
17
     */
18
    public function __construct(Path $path)
19
    {
20
        $this->points = $path->getPoints();
21
        $this->index = 0;
22
    }
23
24
    /**
25
     * @return Line
26
     */
27
    public function current()
28
    {
29
        return new Line($this->points[$this->index], $this->points[$this->index+1]);
30
    }
31
32
    public function next()
33
    {
34
        $this->index++;
35
    }
36
37
    public function key()
38
    {
39
        return $this->index;
40
    }
41
42
    public function valid()
43
    {
44
        return isset($this->points[$this->index]) && isset($this->points[$this->index + 1]);
45
    }
46
47
    public function rewind()
48
    {
49
        $this->index = 0;
50
    }
51
}
52