LineIterator::current()   A
last analyzed

Complexity

Conditions 1
Paths 1

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 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the CGI-Calc package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Cgi\Calc\Point;
13
14
use Cgi\Calc\Point;
15
16
class LineIterator implements \Iterator
17
{
18
    /** @var Point[] */
19
    private $points;
20
21
    /** @var int */
22
    private $index = 0;
23
24
    /**
25
     * @param Path $path
26
     */
27
    public function __construct(Path $path)
28
    {
29
        $this->points = $path->getPoints();
30
        $this->index = 0;
31
    }
32
33
    /**
34
     * @return Line
35
     */
36
    public function current()
37
    {
38
        return new Line($this->points[$this->index], $this->points[$this->index + 1]);
39
    }
40
41
    public function next()
42
    {
43
        ++$this->index;
44
    }
45
46
    public function key()
47
    {
48
        return $this->index;
49
    }
50
51
    public function valid()
52
    {
53
        return isset($this->points[$this->index]) && isset($this->points[$this->index + 1]);
54
    }
55
56
    public function rewind()
57
    {
58
        $this->index = 0;
59
    }
60
}
61