1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Innmind\Immutable; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Simple iterator to cache the results of a generator so it can be iterated |
8
|
|
|
* over multiple times |
9
|
|
|
* |
10
|
|
|
* @template T |
11
|
|
|
* @template S |
12
|
|
|
* @internal Do not use this in your code |
13
|
|
|
*/ |
14
|
|
|
final class Accumulate implements \Iterator |
15
|
|
|
{ |
16
|
|
|
/** @var \Generator<T, S> */ |
17
|
|
|
private \Generator $generator; |
18
|
|
|
/** @var list<T> */ |
|
|
|
|
19
|
|
|
private array $keys = []; |
20
|
|
|
/** @var list<S> */ |
21
|
|
|
private array $values = []; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param \Generator<T, S> $generator |
25
|
|
|
*/ |
26
|
72 |
|
public function __construct(\Generator $generator) |
27
|
|
|
{ |
28
|
72 |
|
$this->generator = $generator; |
29
|
72 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return S |
33
|
|
|
*/ |
34
|
60 |
|
public function current() |
35
|
|
|
{ |
36
|
60 |
|
$this->pop(); |
37
|
|
|
|
38
|
60 |
|
return \current($this->values); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return T |
43
|
|
|
*/ |
44
|
41 |
|
public function key() |
45
|
|
|
{ |
46
|
41 |
|
$this->pop(); |
47
|
|
|
|
48
|
41 |
|
return \current($this->keys); |
49
|
|
|
} |
50
|
|
|
|
51
|
56 |
|
public function next(): void |
52
|
|
|
{ |
53
|
56 |
|
\next($this->keys); |
54
|
56 |
|
\next($this->values); |
55
|
|
|
|
56
|
56 |
|
if ($this->reachedCacheEnd()) { |
57
|
56 |
|
$this->generator->next(); |
58
|
|
|
} |
59
|
56 |
|
} |
60
|
|
|
|
61
|
67 |
|
public function rewind(): void |
62
|
|
|
{ |
63
|
67 |
|
\reset($this->keys); |
64
|
67 |
|
\reset($this->values); |
65
|
67 |
|
} |
66
|
|
|
|
67
|
67 |
|
public function valid(): bool |
68
|
|
|
{ |
69
|
67 |
|
return !$this->reachedCacheEnd() || $this->generator->valid(); |
70
|
|
|
} |
71
|
|
|
|
72
|
67 |
|
private function reachedCacheEnd(): bool |
73
|
|
|
{ |
74
|
67 |
|
return \key($this->values) === null; |
75
|
|
|
} |
76
|
|
|
|
77
|
60 |
|
private function pop(): void |
78
|
|
|
{ |
79
|
60 |
|
if ($this->reachedCacheEnd()) { |
80
|
60 |
|
$this->keys[] = $this->generator->key(); |
81
|
60 |
|
$this->values[] = $this->generator->current(); |
82
|
|
|
} |
83
|
60 |
|
} |
84
|
|
|
} |
85
|
|
|
|
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