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.

Primitive::sort()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 3
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
ccs 1
cts 1
cp 1
crap 1
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
 */
19
final class Primitive implements Implementation
20
{
21
    /** @var Sequence\Implementation<T> */
22
    private Sequence\Implementation $values;
23
24
    /**
25
     * @param Sequence\Implementation<T> $values
26
     */
27
    public function __construct(Sequence\Implementation $values)
28 97
    {
29
        $this->values = $values;
30 97
    }
31 97
32 97
    /**
33 97
     * @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...
34
     *
35 1
     * @return self<T>
36
     */
37 1
    public function __invoke($element): self
38
    {
39
        if ($this->contains($element)) {
40 14
            return $this;
41
        }
42 14
43
        return new self(($this->values)($element));
44
    }
45
46
    /**
47
     * @no-named-arguments
48 1
     * @psalm-pure
49
     *
50 1
     * @template A
51
     *
52
     * @param A $values
0 ignored issues
show
Bug introduced by
The type Innmind\Immutable\Set\A 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...
53
     *
54
     * @return self<A>
55
     */
56 25
    public static function of(...$values): self
57
    {
58 25
        return new self((new Sequence\Primitive($values))->distinct());
59
    }
60
61
    public function size(): int
62
    {
63
        return $this->values->size();
64
    }
65
66 12
    public function count(): int
67
    {
68 12
        return $this->values->size();
69 12
    }
70 12
71
    /**
72
     * @return \Iterator<int, T>
73 12
     */
74
    public function iterator(): \Iterator
75
    {
76
        return $this->values->iterator();
77
    }
78
79
    /**
80
     * @param Implementation<T> $set
81 48
     *
82
     * @return self<T>
83 48
     */
84 5
    public function intersect(Implementation $set): self
85
    {
86
        return new self($this->values->intersect($set->sequence()));
87 48
    }
88 48
89
    /**
90 48
     * @param T $element
91
     */
92
    public function contains($element): bool
93
    {
94
        return $this->values->contains($element);
95
    }
96 50
97
    /**
98 50
     * @param T $element
99
     *
100
     * @return self<T>
101
     */
102
    public function remove($element): self
103
    {
104
        if (!$this->contains($element)) {
105
            return $this;
106 2
        }
107
108 2
        return new self($this->values->filter(
109 1
            static fn($value) => $value !== $element,
110
        ));
111
    }
112 2
113 2
    /**
114 2
     * @param Implementation<T> $set
115 2
     *
116 2
     * @return self<T>
117 2
     */
118
    public function diff(Implementation $set): self
119 2
    {
120
        return new self($this->values->diff($set->sequence()));
121
    }
122
123
    /**
124
     * @param Implementation<T> $set
125
     */
126
    public function equals(Implementation $set): bool
127 2
    {
128
        if ($this->size() !== $set->size()) {
129 2
            return false;
130 2
        }
131 2
132
        return $this->intersect($set)->size() === $this->size();
133
    }
134 2
135
    /**
136
     * @param callable(T): bool $predicate
137
     *
138
     * @return self<T>
139
     */
140 10
    public function filter(callable $predicate): self
141
    {
142 10
        return new self($this->values->filter($predicate));
143 3
    }
144
145
    /**
146 10
     * @param callable(T): void $function
147
     */
148
    public function foreach(callable $function): SideEffect
149
    {
150
        return $this->values->foreach($function);
151
    }
152
153
    /**
154 2
     * @template D
155
     *
156 2
     * @param callable(T): D $discriminator
157 2
     *
158
     * @return Map<D, Set<T>>
159 2
     */
160
    public function groupBy(callable $discriminator): Map
161
    {
162
        return $this
163
            ->values
164
            ->groupBy($discriminator)
165 2
            ->map(static fn(mixed $_, $sequence) => Set::of(...$sequence->toList()));
166
    }
167 2
168 2
    /**
169
     * @template S
170
     *
171
     * @param callable(T): S $function
172
     *
173
     * @return self<S>
174
     */
175
    public function map(callable $function): self
176
    {
177
        return new self($this->values->map($function)->distinct());
178 2
    }
179
180
    /**
181 2
     * @param callable(T): bool $predicate
182
     *
183
     * @return Map<bool, Set<T>>
184
     */
185
    public function partition(callable $predicate): Map
186
    {
187 2
        return $this
188 2
            ->values
189
            ->partition($predicate)
190 2
            ->map(static fn($_, $sequence) => Set::of(...$sequence->toList()));
191 2
    }
192 2
193
    /**
194 2
     * @param callable(T, T): int $function
195
     *
196
     * @return Sequence<T>
197
     */
198
    public function sort(callable $function): Sequence
199
    {
200
        return $this
201
            ->values
202
            ->sort($function)
203 4
            ->toSequence();
204
    }
205
206
    /**
207
     * @param Implementation<T> $set
208
     *
209
     * @return self<T>
210
     */
211 4
    public function merge(Implementation $set): self
212 4
    {
213
        return new self($this->values->append($set->sequence())->distinct());
214 2
    }
215 4
216
    /**
217 4
     * @template R
218 4
     * @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...
219
     * @param callable(R, T): R $reducer
220 4
     *
221 4
     * @return R
222
     */
223
    public function reduce($carry, callable $reducer)
224
    {
225
        return $this->values->reduce($carry, $reducer);
226
    }
227
228
    /**
229
     * @return self<T>
230 2
     */
231
    public function clear(): self
232 2
    {
233
        return self::of();
234
    }
235 2
236 2
    public function empty(): bool
237
    {
238
        return $this->values->empty();
239 2
    }
240 2
241
    public function find(callable $predicate): Maybe
242
    {
243
        return $this->values->find($predicate);
244
    }
245
246 2
    /**
247 2
     * @return Sequence\Implementation<T>
248 2
     */
249
    public function sequence(): Sequence\Implementation
250
    {
251
        return $this->values;
252
    }
253
}
254