Test Failed
Push — 119 ( b892b6...857274 )
by Max
02:48
created

SafeArrayIterator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 0
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
namespace MaxGoryunov\SavingIterator\Src;
4
5
use ArrayAccess;
6
7
/**
8
 * Safe array iterator. Copies array when cloned.
9
 * @template TKey
10
 * @template TValue
11
 * @implements ArrayAccess<TKey, TValue>
12
 * 
13
 * @since 0.3
14
 */
15
final class SafeArrayIterator implements ArrayAccess
16
{
17
18
    /**
19
     * Ctor.
20
     * 
21
     * @phpstan-param array<TKey, TValue> $stored
22
     * @param array<mixed, mixed> $stored array for stored values.
23
     */
24
    public function __construct(
25
        /**
26
         * Array for stored values.
27
         *
28
         * @phpstan-var array<TKey, TValue>
29
         * @var array
30
         */
31
        private array $stored = []
32
    ) {
33
    }
34
35
    /**
36
     * {@inheritDoc}
37
     * @phpstan-param TKey   $offset
38
     * @phpstan-param TValue $value
39
     */
40
    public function offsetSet(mixed $offset, mixed $value): void
41
    {
42
        $this->stored[$offset] = $value;
43
    }
44
45
    /**
46
     * {@inheritDoc}
47
     * @phpstan-param TKey $offset
48
     */
49
    public function offsetGet(mixed $offset): mixed
50
    {
51
        return $this->stored[$offset];
52
    }
53
54
    /**
55
     * {@inheritDoc}
56
     * @phpstan-param TKey $offset
57
     */
58
    public function offsetExists(mixed $offset): bool
59
    {
60
        return array_key_exists($offset, $this->stored);
61
    }
62
63
    /**
64
     * {@inheritDoc}
65
     * @phpstan-param TKey $offset
66
     */
67
    public function offsetUnset(mixed $offset): void
68
    {
69
        unset($this->stored);
70
    }
71
}
72