|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Smoren\ArrayView\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use Smoren\ArrayView\Exceptions\IndexError; |
|
6
|
|
|
use Smoren\ArrayView\Exceptions\KeyError; |
|
7
|
|
|
use Smoren\ArrayView\Exceptions\NotSupportedError; |
|
8
|
|
|
use Smoren\ArrayView\Exceptions\ReadonlyError; |
|
9
|
|
|
use Smoren\ArrayView\Interfaces\ArraySelectorInterface; |
|
10
|
|
|
use Smoren\ArrayView\Interfaces\ArrayViewInterface; |
|
11
|
|
|
use Smoren\ArrayView\Selectors\SliceSelector; |
|
12
|
|
|
use Smoren\ArrayView\Structs\Slice; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @template T |
|
16
|
|
|
*/ |
|
17
|
|
|
trait ArrayViewAccessTrait |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @param numeric|string|ArraySelectorInterface $offset |
|
|
|
|
|
|
21
|
|
|
* |
|
22
|
|
|
* @return bool |
|
23
|
|
|
* |
|
24
|
|
|
* {@inheritDoc} |
|
25
|
|
|
*/ |
|
26
|
|
|
public function offsetExists($offset): bool |
|
27
|
|
|
{ |
|
28
|
|
|
if (\is_numeric($offset)) { |
|
29
|
|
|
return $this->numericOffsetExists($offset); |
|
|
|
|
|
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
if (\is_string($offset) && Slice::isSlice($offset)) { |
|
33
|
|
|
return true; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
if ($offset instanceof ArraySelectorInterface) { |
|
37
|
|
|
return true; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
return false; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param numeric|string|ArraySelectorInterface $offset |
|
45
|
|
|
* |
|
46
|
|
|
* @return T|array<T> |
|
47
|
|
|
* |
|
48
|
|
|
* {@inheritDoc} |
|
49
|
|
|
*/ |
|
50
|
|
|
#[\ReturnTypeWillChange] |
|
51
|
|
|
public function offsetGet($offset) |
|
52
|
|
|
{ |
|
53
|
|
|
/** @var mixed $offset */ |
|
54
|
|
|
if (\is_numeric($offset)) { |
|
55
|
|
|
if (!$this->numericOffsetExists($offset)) { |
|
56
|
|
|
throw new IndexError("Index {$offset} is out of range."); |
|
57
|
|
|
} |
|
58
|
|
|
return $this->source[$this->convertIndex(\intval($offset))]; |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
if (\is_string($offset) && Slice::isSlice($offset)) { |
|
62
|
|
|
return $this->subview(new SliceSelector($offset))->toArray(); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if ($offset instanceof ArraySelectorInterface) { |
|
66
|
|
|
return $this->subview($offset)->toArray(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$strOffset = \is_scalar($offset) ? \strval($offset) : \gettype($offset); |
|
70
|
|
|
throw new KeyError("Invalid key: \"{$strOffset}\"."); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param numeric|string|ArraySelectorInterface $offset |
|
75
|
|
|
* @param T|array<T>|ArrayViewInterface<T> $value |
|
|
|
|
|
|
76
|
|
|
* |
|
77
|
|
|
* @return void |
|
78
|
|
|
* |
|
79
|
|
|
* {@inheritDoc} |
|
80
|
|
|
*/ |
|
81
|
|
|
public function offsetSet($offset, $value): void |
|
82
|
|
|
{ |
|
83
|
|
|
/** @var mixed $offset */ |
|
84
|
|
|
if ($this->isReadonly()) { |
|
|
|
|
|
|
85
|
|
|
throw new ReadonlyError("Cannot modify a readonly view."); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
if (\is_numeric($offset)) { |
|
89
|
|
|
if (!$this->numericOffsetExists($offset)) { |
|
90
|
|
|
throw new IndexError("Index {$offset} is out of range."); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
// @phpstan-ignore-next-line |
|
94
|
|
|
$this->source[$this->convertIndex(\intval($offset))] = $value; |
|
|
|
|
|
|
95
|
|
|
return; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
if (\is_string($offset) && Slice::isSlice($offset)) { |
|
99
|
|
|
/** @var array<T>|ArrayViewInterface<T> $value */ |
|
100
|
|
|
$this->subview(new SliceSelector($offset))->set($value); |
|
101
|
|
|
return; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
if ($offset instanceof ArraySelectorInterface) { |
|
105
|
|
|
$this->subview($offset)->set($value); |
|
106
|
|
|
return; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
$strOffset = \is_scalar($offset) ? \strval($offset) : \gettype($offset); |
|
110
|
|
|
throw new KeyError("Invalid key: \"{$strOffset}\"."); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @param numeric|string|ArraySelectorInterface $offset |
|
115
|
|
|
* |
|
116
|
|
|
* @return void |
|
117
|
|
|
* |
|
118
|
|
|
* @throws NotSupportedError |
|
119
|
|
|
* |
|
120
|
|
|
* {@inheritDoc} |
|
121
|
|
|
*/ |
|
122
|
|
|
public function offsetUnset($offset): void |
|
|
|
|
|
|
123
|
|
|
{ |
|
124
|
|
|
throw new NotSupportedError(); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
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