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

Iterator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 65
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A current() 0 3 1
A rewind() 0 3 1
A next() 0 3 1
A key() 0 3 1
A valid() 0 3 2
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