1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MaxGoryunov\SavingIterator\Src; |
4
|
|
|
|
5
|
|
|
use Iterator; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Iterator which stores iterated values. |
9
|
|
|
* @template TKey |
10
|
|
|
* @template TValue |
11
|
|
|
* @implements Iterator<TKey, TValue> |
12
|
|
|
*/ |
13
|
|
|
class SavingIterator implements Iterator |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Ctor. |
18
|
|
|
* |
19
|
|
|
* @phpstan-param Iterator<TKey, TValue> $origin |
20
|
|
|
* @phpstan-param AddingIterator<TKey, TValue> $target |
21
|
|
|
* @param Iterator $origin original iterator. |
22
|
|
|
* @param AddingIterator $target iterator to which the values are saved. |
23
|
|
|
*/ |
24
|
|
|
public function __construct( |
25
|
|
|
/** |
26
|
|
|
* Original iterator. |
27
|
|
|
* |
28
|
|
|
* @phpstan-var Iterator<TKey, TValue> |
29
|
|
|
* @var Iterator |
30
|
|
|
*/ |
31
|
|
|
private Iterator $origin, |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Iterator to which the values are saved. |
35
|
|
|
* |
36
|
|
|
* @phpstan-var AddingIterator<TKey, TValue> |
37
|
|
|
* @var AddingIterator |
38
|
|
|
*/ |
39
|
|
|
private AddingIterator $target |
40
|
|
|
) { |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Returns target after adding a value from origin. |
45
|
|
|
* |
46
|
|
|
* @phpstan-return AddingIterator<TKey, TValue> |
47
|
|
|
* @return AddingIterator |
48
|
|
|
*/ |
49
|
|
|
private function added(): AddingIterator |
50
|
|
|
{ |
51
|
|
|
/** |
52
|
|
|
* @todo #85:40min There is a private function in this class. It should |
53
|
|
|
* be removed without creating the code duplication problem again. |
54
|
|
|
*/ |
55
|
|
|
$this->target = $this->target->from($this->origin); |
56
|
|
|
return $this->target; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritDoc} |
61
|
|
|
* @return TValue|false |
|
|
|
|
62
|
|
|
*/ |
63
|
|
|
public function current(): mixed |
64
|
|
|
{ |
65
|
|
|
return $this->added()->current(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritDoc} |
70
|
|
|
* @return TKey|null |
|
|
|
|
71
|
|
|
*/ |
72
|
|
|
public function key(): mixed |
73
|
|
|
{ |
74
|
|
|
return $this->added()->key(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* {@inheritDoc} |
79
|
|
|
*/ |
80
|
|
|
public function valid(): bool |
81
|
|
|
{ |
82
|
|
|
return ($this->origin->valid()) || ($this->target->valid()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritDoc} |
87
|
|
|
*/ |
88
|
|
|
public function next(): void |
89
|
|
|
{ |
90
|
|
|
if ($this->origin->valid()) { |
91
|
|
|
$this->origin->next(); |
92
|
|
|
} |
93
|
|
|
$this->target->next(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* {@inheritDoc} |
98
|
|
|
*/ |
99
|
|
|
public function rewind(): void |
100
|
|
|
{ |
101
|
|
|
$this->target->rewind(); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths