|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace loophp\collection\Iterator; |
|
6
|
|
|
|
|
7
|
|
|
use Iterator; |
|
8
|
|
|
use Psr\Cache\CacheItemInterface; |
|
9
|
|
|
use Psr\Cache\CacheItemPoolInterface; |
|
10
|
|
|
use ReturnTypeWillChange; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @internal |
|
14
|
|
|
* |
|
15
|
|
|
* @template TKey |
|
16
|
|
|
* @template T |
|
17
|
|
|
* |
|
18
|
|
|
* @implements Iterator<TKey, T> |
|
19
|
|
|
*/ |
|
20
|
|
|
final class PsrCacheIterator implements Iterator |
|
21
|
|
|
{ |
|
22
|
|
|
private int $key = 0; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param Iterator<TKey, T> $iterator |
|
26
|
|
|
*/ |
|
27
|
4 |
|
public function __construct(private Iterator $iterator, private CacheItemPoolInterface $cache) {} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @return T |
|
|
|
|
|
|
31
|
|
|
*/ |
|
32
|
4 |
|
#[ReturnTypeWillChange] |
|
33
|
|
|
public function current() |
|
34
|
|
|
{ |
|
35
|
|
|
/** @var array{TKey, T} $data */ |
|
36
|
4 |
|
$data = $this->getTupleFromCache($this->key)->get(); |
|
37
|
|
|
|
|
38
|
4 |
|
return $data[1]; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return TKey |
|
|
|
|
|
|
43
|
|
|
*/ |
|
44
|
3 |
|
#[ReturnTypeWillChange] |
|
45
|
|
|
public function key() |
|
46
|
|
|
{ |
|
47
|
|
|
/** @var array{TKey, T} $data */ |
|
48
|
3 |
|
$data = $this->getTupleFromCache($this->key)->get(); |
|
49
|
|
|
|
|
50
|
3 |
|
return $data[0]; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
4 |
|
public function next(): void |
|
54
|
|
|
{ |
|
55
|
|
|
// This is mostly for iterator_count(). |
|
56
|
4 |
|
$this->getTupleFromCache($this->key++); |
|
57
|
|
|
|
|
58
|
4 |
|
$this->iterator->next(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
4 |
|
public function rewind(): void |
|
62
|
|
|
{ |
|
63
|
|
|
// No call to $this->iterator->rewind() because we do not know if the inner |
|
64
|
|
|
// iterator can be rewinded or not. |
|
65
|
4 |
|
$this->key = 0; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
3 |
|
public function valid(): bool |
|
69
|
|
|
{ |
|
70
|
3 |
|
return $this->iterator->valid() || $this->cache->hasItem((string) $this->key); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
4 |
|
private function getTupleFromCache(int $key): CacheItemInterface |
|
74
|
|
|
{ |
|
75
|
4 |
|
$item = $this->cache->getItem((string) $key); |
|
76
|
|
|
|
|
77
|
4 |
|
if (false === $item->isHit()) { |
|
78
|
4 |
|
$item->set([ |
|
79
|
4 |
|
$this->iterator->key(), |
|
80
|
4 |
|
$this->iterator->current(), |
|
81
|
4 |
|
]); |
|
82
|
|
|
|
|
83
|
4 |
|
$this->cache->save($item); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
4 |
|
return $item; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
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