Failed Conditions
Push — master ( 02f37d...f95322 )
by Adrien
09:26
created

Iterator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Worksheet;
4
5
use PhpOffice\PhpSpreadsheet\Spreadsheet;
6
7
class Iterator implements \Iterator
8
{
9
    /**
10
     * Spreadsheet to iterate.
11
     *
12
     * @var Spreadsheet
13
     */
14
    private $subject;
15
16
    /**
17
     * Current iterator position.
18
     *
19
     * @var int
20
     */
21
    private $position = 0;
22
23
    /**
24
     * Create a new worksheet iterator.
25
     */
26 393
    public function __construct(Spreadsheet $subject)
27
    {
28
        // Set subject
29 393
        $this->subject = $subject;
30 393
    }
31
32
    /**
33
     * Rewind iterator.
34
     */
35 393
    public function rewind(): void
36
    {
37 393
        $this->position = 0;
38 393
    }
39
40
    /**
41
     * Current Worksheet.
42
     */
43 393
    public function current(): Worksheet
44
    {
45 393
        return $this->subject->getSheet($this->position);
46
    }
47
48
    /**
49
     * Current key.
50
     */
51 1
    public function key(): int
52
    {
53 1
        return $this->position;
54
    }
55
56
    /**
57
     * Next value.
58
     */
59 393
    public function next(): void
60
    {
61 393
        ++$this->position;
62 393
    }
63
64
    /**
65
     * Are there more Worksheet instances available?
66
     *
67
     * @return bool
68
     */
69 393
    public function valid()
70
    {
71 393
        return $this->position < $this->subject->getSheetCount() && $this->position >= 0;
72
    }
73
}
74