Passed
Push — develop ( 125f46...5e090d )
by Adrien
26:19
created

Iterator::__destruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
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 0
dl 0
loc 3
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
     * @param Spreadsheet $subject
27
     */
28 112
    public function __construct(Spreadsheet $subject)
29
    {
30
        // Set subject
31 112
        $this->subject = $subject;
32 112
    }
33
34
    /**
35
     * Destructor.
36
     */
37 112
    public function __destruct()
38
    {
39 112
        unset($this->subject);
40 112
    }
41
42
    /**
43
     * Rewind iterator.
44
     */
45 112
    public function rewind()
46
    {
47 112
        $this->position = 0;
48 112
    }
49
50
    /**
51
     * Current Worksheet.
52
     *
53
     * @return Worksheet
54
     */
55 112
    public function current()
56
    {
57 112
        return $this->subject->getSheet($this->position);
58
    }
59
60
    /**
61
     * Current key.
62
     *
63
     * @return int
64
     */
65 1
    public function key()
66
    {
67 1
        return $this->position;
68
    }
69
70
    /**
71
     * Next value.
72
     */
73 112
    public function next()
74
    {
75 112
        ++$this->position;
76 112
    }
77
78
    /**
79
     * Are there more Worksheet instances available?
80
     *
81
     * @return bool
82
     */
83 112
    public function valid()
84
    {
85 112
        return $this->position < $this->subject->getSheetCount() && $this->position >= 0;
86
    }
87
}
88