|
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
|
|
|
* Veil for Adding Iterator. |
|
18
|
|
|
* Veil is added so that 'from' method is not called manually on methods |
|
19
|
|
|
* 'current' and 'key'. |
|
20
|
|
|
* |
|
21
|
|
|
* @phpstan-var Indifferent<AddingIterator<TKey, TValue>> |
|
22
|
|
|
* @var Indifferent |
|
23
|
|
|
*/ |
|
24
|
|
|
private Indifferent $target; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Ctor. |
|
28
|
|
|
* |
|
29
|
|
|
* @phpstan-param Iterator<TKey, TValue> $origin |
|
30
|
|
|
* @phpstan-param AddingIterator<TKey, TValue> $target |
|
31
|
|
|
* @param Iterator $origin original iterator. |
|
32
|
|
|
* @param AddingIterator $target iterator to which the values are saved. |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct( |
|
35
|
|
|
/** |
|
36
|
|
|
* Original iterator. |
|
37
|
|
|
* |
|
38
|
|
|
* @phpstan-var Iterator<TKey, TValue> |
|
39
|
|
|
* @var Iterator |
|
40
|
|
|
*/ |
|
41
|
|
|
private Iterator $origin, |
|
42
|
|
|
AddingIterator $target |
|
43
|
|
|
) { |
|
44
|
|
|
$this->target = new ContextVeil( |
|
45
|
|
|
$target, |
|
46
|
|
|
fn (AddingIterator $stored): AddingIterator => $stored->from( |
|
47
|
|
|
$this->origin |
|
48
|
|
|
), |
|
49
|
|
|
array_flip(["current", "key"]) |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* {@inheritDoc} |
|
55
|
|
|
* @return TValue|false |
|
|
|
|
|
|
56
|
|
|
*/ |
|
57
|
|
|
public function current(): mixed |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->target->current(); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* {@inheritDoc} |
|
64
|
|
|
* @return TKey|null |
|
|
|
|
|
|
65
|
|
|
*/ |
|
66
|
|
|
public function key(): mixed |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->target->key(); |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* {@inheritDoc} |
|
73
|
|
|
*/ |
|
74
|
|
|
public function valid(): bool |
|
75
|
|
|
{ |
|
76
|
|
|
return ($this->origin->valid()) || ($this->target->valid()); |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* {@inheritDoc} |
|
81
|
|
|
*/ |
|
82
|
|
|
public function next(): void |
|
83
|
|
|
{ |
|
84
|
|
|
if ($this->origin->valid()) { |
|
85
|
|
|
$this->origin->next(); |
|
86
|
|
|
} |
|
87
|
|
|
$this->target->next(); |
|
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* {@inheritDoc} |
|
92
|
|
|
*/ |
|
93
|
|
|
public function rewind(): void |
|
94
|
|
|
{ |
|
95
|
|
|
$this->target->rewind(); |
|
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
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