Iterator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Jobles\Core;
4
5
final class Iterator implements \Iterator, \Countable
6
{
7
8
    /**
9
     * @var int
10
     */
11
    private $position = 0;
12
13
    /**
14
     * @var AbstractCollection
15
     */
16
    private $data;
17
18 12
    public function __construct(AbstractCollection $collection)
19
    {
20 12
        $this->data = $collection;
21 12
    }
22
23
    /**
24
     * @return mixed
25
     */
26 2
    public function current()
27
    {
28 2
        return $this->data->pick($this->position);
29
    }
30
31
    /**
32
     * @inheritDoc
33
     */
34 6
    public function next()
35
    {
36 6
        ++$this->position;
37 6
    }
38
39
    /**
40
     * @return int
41
     */
42 1
    public function key() : int
43
    {
44 1
        return $this->position;
45
    }
46
47
    /**
48
     * @return bool
49
     */
50 2
    public function valid() : bool
51
    {
52 2
        return $this->position < $this->count();
53
    }
54
55
    /**
56
     * @return int
57
     */
58 3
    public function count() : int
59
    {
60 3
        return count($this->data);
61
    }
62
63
    /**
64
     * @inheritDoc
65
     */
66 1
    public function rewind()
67
    {
68 1
        $this->position = 0;
69 1
    }
70
}
71