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.
Completed
Push — develop ( 8f1ca2...5cfe3e )
by Baptiste
03:36
created

Map::offsetSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Immutable;
5
6
use Innmind\Immutable\{
7
    Exception\InvalidArgumentException,
8
    Exception\LogicException,
9
    Exception\ElementNotFoundException,
10
    Exception\GroupEmptyMapException
11
};
12
13
final class Map implements MapInterface
14
{
15
    private $implementation;
16
17
    /**
18
     * {@inheritdoc}
19
     */
20 98
    public function __construct(string $keyType, string $valueType)
21
    {
22 98
        $type = Type::of($keyType);
23
24 98
        if ($type instanceof ClassType) {
0 ignored issues
show
Bug introduced by
The type Innmind\Immutable\ClassType 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...
25
            $this->implementation = new Map\ObjectKeys($keyType, $valueType);
26 98
        } else if (\in_array($keyType, ['int', 'integer', 'string'], true)) {
27 76
            $this->implementation = new Map\Primitive($keyType, $valueType);
28
        } else {
29 26
            $this->implementation = new Map\DoubleIndex($keyType, $valueType);
30
        }
31 98
    }
32
33 22
    public static function of(
34
        string $key,
35
        string $value,
36
        array $keys = [],
37
        array $values = []
38
    ): self {
39 22
        $keys = \array_values($keys);
40 22
        $values = \array_values($values);
41
42 22
        if (\count($keys) !== \count($values)) {
43 2
            throw new LogicException('Different sizes of keys and values');
44
        }
45
46 20
        $self = new self($key, $value);
47
48 20
        foreach ($keys as $i => $key) {
49 2
            $self = $self->put($key, $values[$i]);
50
        }
51
52 20
        return $self;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 46
    public function keyType(): Str
59
    {
60 46
        return $this->implementation->keyType();
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 44
    public function valueType(): Str
67
    {
68 44
        return $this->implementation->valueType();
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74 22
    public function size(): int
75
    {
76 22
        return $this->implementation->size();
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82 6
    public function count(): int
83
    {
84 6
        return $this->implementation->count();
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90 2
    public function current()
91
    {
92 2
        return $this->implementation->current();
93
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98 2
    public function key()
99
    {
100 2
        return $this->implementation->key();
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106 2
    public function next()
107
    {
108 2
        $this->implementation->next();
109 2
    }
110
111
    /**
112
     * {@inheritdoc}
113
     */
114 2
    public function rewind()
115
    {
116 2
        $this->implementation->rewind();
117 2
    }
118
119
    /**
120
     * {@inheritdoc}
121
     */
122 2
    public function valid()
123
    {
124 2
        return $this->implementation->valid();
125
    }
126
127
    /**
128
     * {@inheritdoc}
129
     */
130 2
    public function offsetExists($offset): bool
131
    {
132 2
        return $this->implementation->offsetExists($offset);
133
    }
134
135
    /**
136
     * {@inheritdoc}
137
     */
138 8
    public function offsetGet($offset)
139
    {
140 8
        return $this->implementation->offsetGet($offset);
141
    }
142
143
    /**
144
     * {@inheritdoc}
145
     */
146 2
    public function offsetSet($offset, $value)
147
    {
148 2
        throw new LogicException('You can\'t modify a map');
149
    }
150
151
    /**
152
     * {@inheritdoc}
153
     */
154 2
    public function offsetUnset($offset)
155
    {
156 2
        throw new LogicException('You can\'t modify a map');
157
    }
158
159
    /**
160
     * {@inheritdoc}
161
     */
162 82
    public function put($key, $value): MapInterface
163
    {
164 82
        $map = clone $this;
165 82
        $map->implementation = $this->implementation->put($key, $value);
166
167 76
        return $map;
168
    }
169
170
    /**
171
     * Alias for put method in order to have a syntax similar to a true tuple
172
     * when constructing the map
173
     *
174
     * Example:
175
     * <code>
176
     * Map::of('int', 'int')
177
     *     (1, 2)
178
     *     (3, 4)
179
     * </code>
180
     *
181
     * @param T $key
182
     * @param S $value
183
     *
184
     * @return self<T, S>
185
     */
186 16
    public function __invoke($key, $value): self
187
    {
188 16
        return $this->put($key, $value);
189
    }
190
191
    /**
192
     * {@inheritdoc}
193
     */
194 46
    public function get($key)
195
    {
196 46
        return $this->implementation->get($key);
197
    }
198
199
    /**
200
     * {@inheritdoc}
201
     */
202 26
    public function contains($key): bool
203
    {
204 26
        return $this->implementation->contains($key);
205
    }
206
207
    /**
208
     * {@inheritdoc}
209
     */
210 10
    public function clear(): MapInterface
211
    {
212 10
        $map = clone $this;
213 10
        $map->implementation = $this->implementation->clear();
214
215 10
        return $map;
216
    }
217
218
    /**
219
     * {@inheritdoc}
220
     */
221 12
    public function equals(MapInterface $map): bool
222
    {
223 12
        return $this->implementation->equals($map);
224
    }
225
226
    /**
227
     * {@inheritdoc}
228
     */
229 2
    public function filter(callable $predicate): MapInterface
230
    {
231 2
        $map = $this->clear();
232 2
        $map->implementation = $this->implementation->filter($predicate);
233
234 2
        return $map;
235
    }
236
237
    /**
238
     * {@inheritdoc}
239
     */
240 2
    public function foreach(callable $function): MapInterface
241
    {
242 2
        $this->implementation->foreach($function);
243
244 2
        return $this;
245
    }
246
247
    /**
248
     * {@inheritdoc}
249
     */
250 4
    public function groupBy(callable $discriminator): MapInterface
251
    {
252 4
        return $this->implementation->groupBy($discriminator);
253
    }
254
255
    /**
256
     * {@inheritdoc}
257
     */
258 22
    public function keys(): SetInterface
259
    {
260 22
        return $this->implementation->keys();
261
    }
262
263
    /**
264
     * {@inheritdoc}
265
     */
266 10
    public function values(): StreamInterface
267
    {
268 10
        return $this->implementation->values();
269
    }
270
271
    /**
272
     * {@inheritdoc}
273
     */
274 6
    public function map(callable $function): MapInterface
275
    {
276 6
        $map = $this->clear();
277 6
        $map->implementation = $this->implementation->map($function);
278
279 2
        return $map;
280
    }
281
282
    /**
283
     * {@inheritdoc}
284
     */
285 2
    public function join(string $separator): Str
286
    {
287 2
        return $this->implementation->join($separator);
288
    }
289
290
    /**
291
     * {@inheritdoc}
292
     */
293 2
    public function remove($key): MapInterface
294
    {
295 2
        $map = clone $this;
296 2
        $map->implementation = $this->implementation->remove($key);
297
298 2
        return $map;
299
    }
300
301
    /**
302
     * {@inheritdoc}
303
     */
304 4
    public function merge(MapInterface $map): MapInterface
305
    {
306 4
        $self = clone $this;
307 4
        $self->implementation = $this->implementation->merge($map);
308
309 2
        return $self;
310
    }
311
312
    /**
313
     * {@inheritdoc}
314
     */
315 2
    public function partition(callable $predicate): MapInterface
316
    {
317 2
        return $this->implementation->partition($predicate);
318
    }
319
320
    /**
321
     * {@inheritdoc}
322
     */
323 6
    public function reduce($carry, callable $reducer)
324
    {
325 6
        return $this->implementation->reduce($carry, $reducer);
326
    }
327
}
328