Total Complexity | 14 |
Total Lines | 110 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
12 | class StepsIterator implements \Iterator |
||
13 | { |
||
14 | /** |
||
15 | * @var \Iterator |
||
16 | */ |
||
17 | private $inner; |
||
18 | |||
19 | /** |
||
20 | * @var int |
||
21 | */ |
||
22 | private $index; |
||
23 | |||
24 | /** |
||
25 | * @var Step |
||
26 | */ |
||
27 | private $current; |
||
28 | |||
29 | /** |
||
30 | * @var bool override trigger: manual in iteration |
||
31 | */ |
||
32 | private $noManual = false; |
||
33 | |||
34 | /** |
||
35 | * StepsIterator constructor. |
||
36 | * |
||
37 | * @param \Iterator $iterator |
||
38 | */ |
||
39 | 3 | public function __construct(\Iterator $iterator) |
|
40 | { |
||
41 | 3 | $this->inner = $iterator; |
|
42 | 3 | } |
|
43 | |||
44 | /** |
||
45 | * @return null|int |
||
46 | */ |
||
47 | 1 | public function getIndex() |
|
48 | { |
||
49 | 1 | return $this->index; |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * Index of the pipeline step being iterated |
||
54 | * |
||
55 | * Undefined behaviour if the iteration has not yet been |
||
56 | * started (e.g. the iterator has not yet been rewound) |
||
57 | * |
||
58 | * @return int |
||
59 | */ |
||
60 | 1 | public function getStepIndex() |
|
61 | { |
||
62 | 1 | return $this->current->getIndex(); |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * Iteration might stop at a manual step. If |
||
67 | * that is the case, isManual() will be true |
||
68 | * *after* the iteration. |
||
69 | * |
||
70 | * @return bool |
||
71 | */ |
||
72 | 2 | public function isManual() |
|
73 | { |
||
74 | 2 | return 0 !== $this->index |
|
75 | 2 | && !$this->noManual |
|
76 | 2 | && $this->current() |
|
77 | 2 | && $this->current->isManual(); |
|
78 | } |
||
79 | |||
80 | /** @see \Iterator * */ |
||
81 | |||
82 | 2 | public function next() |
|
83 | { |
||
84 | 2 | $this->index++; |
|
85 | 2 | $this->inner->next(); |
|
86 | 2 | } |
|
87 | |||
88 | 2 | public function key() |
|
89 | { |
||
90 | 2 | return $this->inner->key(); |
|
91 | } |
||
92 | |||
93 | /** |
||
94 | * @return Step |
||
95 | */ |
||
96 | 2 | public function current() |
|
97 | { |
||
98 | 2 | return $this->current = $this->inner->current(); |
|
99 | } |
||
100 | |||
101 | 2 | public function valid() |
|
102 | { |
||
103 | 2 | if ($this->isManual()) { |
|
104 | 1 | return false; |
|
105 | } |
||
106 | |||
107 | 2 | return $this->inner->valid(); |
|
108 | } |
||
109 | |||
110 | 2 | public function rewind() |
|
114 | 2 | } |
|
115 | |||
116 | /** |
||
117 | * @param bool $noManual |
||
118 | */ |
||
119 | 1 | public function setNoManual($noManual) |
|
122 | 1 | } |
|
123 | } |
||
124 |