GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Lazy::foreach()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Immutable\Set;
5
6
use Innmind\Immutable\{
7
    Map,
8
    Sequence,
9
    Set,
10
    Str,
11
    Maybe,
12
    SideEffect,
13
};
14
15
/**
16
 * @template T
17
 * @psalm-immutable
18
 * @psalm-type RegisterCleanup = callable(callable(): void): void
19
 */
20
final class Lazy implements Implementation
21
{
22
    /** @var Sequence\Implementation<T> */
23
    private Sequence\Implementation $values;
24
25
    /**
26
     * @param Sequence\Implementation<T> $values
27
     */
28
    public function __construct(Sequence\Implementation $values)
29
    {
30
        $this->values = $values->distinct();
31
    }
32
33
    /**
34
     * @param T $element
0 ignored issues
show
Bug introduced by
The type Innmind\Immutable\Set\T was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
35
     *
36
     * @return self<T>
37
     */
38
    public function __invoke($element): self
39
    {
40
        return new self(($this->values)($element));
41
    }
42
43
    /**
44
     * @template A
45
     * @psalm-pure
46
     *
47
     * @param callable(RegisterCleanup): \Generator<A> $generator
48
     *
49
     * @return self<A>
50
     */
51
    public static function of(callable $generator): self
52
    {
53
        return new self(new Sequence\Lazy($generator));
54
    }
55
56
    public function size(): int
57
    {
58
        return $this->values->size();
59
    }
60
61
    public function count(): int
62
    {
63
        return $this->values->size();
64
    }
65
66
    /**
67
     * @return \Iterator<int, T>
68
     */
69
    public function iterator(): \Iterator
70
    {
71
        return $this->values->iterator();
72
    }
73
74
    /**
75
     * @param Implementation<T> $set
76
     *
77
     * @return self<T>
78
     */
79
    public function intersect(Implementation $set): self
80
    {
81
        if ($this === $set) {
0 ignored issues
show
introduced by
The condition $this === $set is always false.
Loading history...
82
            // this is necessary as the manipulation of the same iterator below
83
            // leads to unexpected behaviour
84
            return $this;
85
        }
86
87
        return new self($this->values->intersect($set->sequence()));
88
    }
89
90
    /**
91
     * @param T $element
92
     */
93
    public function contains($element): bool
94
    {
95
        return $this->values->contains($element);
96
    }
97
98
    /**
99
     * @param T $element
100
     *
101
     * @return self<T>
102
     */
103
    public function remove($element): self
104
    {
105
        if (!$this->contains($element)) {
106
            return $this;
107
        }
108
109
        return new self($this->values->filter(
110
            static fn($value) => $value !== $element,
111
        ));
112
    }
113
114
    /**
115
     * @param Implementation<T> $set
116
     *
117
     * @return self<T>
118
     */
119
    public function diff(Implementation $set): self
120
    {
121
        return new self($this->values->diff($set->sequence()));
122
    }
123
124
    /**
125
     * @param Implementation<T> $set
126
     */
127
    public function equals(Implementation $set): bool
128
    {
129
        if ($this->size() !== $set->size()) {
130
            return false;
131
        }
132
133
        return $this->intersect($set)->size() === $this->size();
134
    }
135
136
    /**
137
     * @param callable(T): bool $predicate
138
     *
139
     * @return self<T>
140
     */
141
    public function filter(callable $predicate): self
142
    {
143
        return new self($this->values->filter($predicate));
144
    }
145
146
    /**
147
     * @param callable(T): void $function
148
     */
149
    public function foreach(callable $function): SideEffect
150
    {
151
        return $this->values->foreach($function);
152
    }
153
154
    /**
155
     * @template D
156
     *
157
     * @param callable(T): D $discriminator
158
     *
159
     * @return Map<D, Set<T>>
160
     */
161
    public function groupBy(callable $discriminator): Map
162
    {
163
        return $this
164
            ->values
165
            ->groupBy($discriminator)
166
            ->map(static fn(mixed $_, $sequence) => Set::of(...$sequence->toList()));
167
    }
168
169
    /**
170
     * @template S
171
     *
172
     * @param callable(T): S $function
173
     *
174
     * @return self<S>
175
     */
176
    public function map(callable $function): self
177
    {
178
        return new self($this->values->map($function));
179
    }
180
181
    /**
182
     * @param callable(T): bool $predicate
183
     *
184
     * @return Map<bool, Set<T>>
185
     */
186
    public function partition(callable $predicate): Map
187
    {
188
        return $this
189
            ->values
190
            ->partition($predicate)
191
            ->map(static fn($_, $sequence) => Set::of(...$sequence->toList()));
192
    }
193
194
    /**
195
     * @param callable(T, T): int $function
196
     *
197
     * @return Sequence<T>
198
     */
199
    public function sort(callable $function): Sequence
200
    {
201
        return $this
202
            ->values
203
            ->sort($function)
204
            ->toSequence();
205
    }
206
207
    /**
208
     * @param Implementation<T> $set
209
     *
210
     * @return self<T>
211
     */
212
    public function merge(Implementation $set): self
213
    {
214
        return new self($this->values->append($set->sequence()));
215
    }
216
217
    /**
218
     * @template R
219
     * @param R $carry
0 ignored issues
show
Bug introduced by
The type Innmind\Immutable\Set\R was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
220
     * @param callable(R, T): R $reducer
221
     *
222
     * @return R
223
     */
224
    public function reduce($carry, callable $reducer)
225
    {
226
        return $this->values->reduce($carry, $reducer);
227
    }
228
229
    /**
230
     * @return Implementation<T>
231
     */
232
    public function clear(): Implementation
233
    {
234
        return Primitive::of();
235
    }
236
237
    public function empty(): bool
238
    {
239
        return $this->values->empty();
240
    }
241
242
    public function find(callable $predicate): Maybe
243
    {
244
        return $this->values->find($predicate);
245
    }
246
247
    /**
248
     * @return Sequence\Implementation<T>
249
     */
250
    public function sequence(): Sequence\Implementation
251
    {
252
        return $this->values;
253
    }
254
}
255