1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bdf\Prime\Connection\Result; |
4
|
|
|
|
5
|
|
|
use ArrayIterator; |
6
|
|
|
use Bdf\Prime\Connection\Result\FetchStrategy\ArrayFetchStrategyInterface; |
7
|
|
|
use Bdf\Prime\Connection\Result\FetchStrategy\AssociativeArrayFetch; |
8
|
|
|
use Bdf\Prime\Connection\Result\FetchStrategy\ClassArrayFetch; |
9
|
|
|
use Bdf\Prime\Connection\Result\FetchStrategy\ColumnArrayFetch; |
10
|
|
|
use Bdf\Prime\Connection\Result\FetchStrategy\ListArrayFetch; |
11
|
|
|
use Bdf\Prime\Connection\Result\FetchStrategy\ObjectArrayFetch; |
12
|
|
|
use Bdf\Prime\Exception\DBALException; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Wrap simple associative array to ResultSet |
16
|
|
|
* This result is useful for caches |
17
|
|
|
* |
18
|
|
|
* @template T |
19
|
|
|
* @implements ResultSetInterface<T> |
20
|
|
|
*/ |
21
|
|
|
final class ArrayResultSet extends ArrayIterator implements ResultSetInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var ArrayFetchStrategyInterface<T> |
25
|
|
|
*/ |
26
|
|
|
private ArrayFetchStrategyInterface $strategy; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param list<array<string, mixed>> $array |
|
|
|
|
30
|
|
|
* @param int $flags |
31
|
|
|
* @psalm-this-out ArrayResultSet<array<string, mixed>> |
32
|
|
|
*/ |
33
|
44 |
|
public function __construct($array = [], $flags = 0) |
34
|
|
|
{ |
35
|
44 |
|
parent::__construct($array, $flags); |
|
|
|
|
36
|
|
|
|
37
|
|
|
/** @var ArrayResultSet<array<string, mixed>> $this */ |
38
|
44 |
|
$this->strategy = AssociativeArrayFetch::instance(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
6 |
|
public function fetchMode($mode, $options = null) |
45
|
|
|
{ |
46
|
|
|
switch ($mode) { |
47
|
6 |
|
case self::FETCH_ASSOC: |
|
|
|
|
48
|
1 |
|
return $this->asAssociative(); |
49
|
|
|
|
50
|
5 |
|
case self::FETCH_NUM: |
|
|
|
|
51
|
1 |
|
return $this->asList(); |
52
|
|
|
|
53
|
4 |
|
case self::FETCH_COLUMN: |
|
|
|
|
54
|
2 |
|
return $this->asColumn($options ?? 0); |
55
|
|
|
|
56
|
2 |
|
case self::FETCH_OBJECT: |
|
|
|
|
57
|
1 |
|
return $this->asObject(); |
58
|
|
|
|
59
|
1 |
|
case self::FETCH_CLASS: |
|
|
|
|
60
|
1 |
|
return $this->asClass($options); |
61
|
|
|
|
62
|
|
|
default: |
63
|
|
|
throw new DBALException('Unsupported fetch mode ' . $mode); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
1 |
|
public function asAssociative(): ResultSetInterface |
71
|
|
|
{ |
72
|
|
|
/** @var ArrayResultSet<array<string, mixed>> $this */ |
73
|
1 |
|
$this->strategy = AssociativeArrayFetch::instance(); |
74
|
|
|
|
75
|
1 |
|
return $this; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritdoc} |
80
|
|
|
*/ |
81
|
2 |
|
public function asList(): ResultSetInterface |
82
|
|
|
{ |
83
|
|
|
/** @var ArrayResultSet<list<mixed>> $this */ |
84
|
2 |
|
$this->strategy = ListArrayFetch::instance(); |
85
|
|
|
|
86
|
2 |
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* {@inheritdoc} |
91
|
|
|
*/ |
92
|
2 |
|
public function asObject(): ResultSetInterface |
93
|
|
|
{ |
94
|
|
|
/** @var ArrayResultSet<\stdClass> $this */ |
95
|
2 |
|
$this->strategy = ObjectArrayFetch::instance(); |
96
|
|
|
|
97
|
2 |
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* {@inheritdoc} |
102
|
|
|
* |
103
|
|
|
* @param class-string<E> $className |
|
|
|
|
104
|
|
|
* @param list<mixed> $constructorArguments |
105
|
|
|
* |
106
|
|
|
* @return static<E> |
107
|
|
|
* |
108
|
|
|
* @template E |
109
|
|
|
*/ |
110
|
2 |
|
public function asClass(string $className, array $constructorArguments = []): ResultSetInterface |
111
|
|
|
{ |
112
|
|
|
/** @var ArrayResultSet<E> $this */ |
113
|
2 |
|
$this->strategy = new ClassArrayFetch($className, $constructorArguments); |
114
|
|
|
|
115
|
2 |
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* {@inheritdoc} |
120
|
|
|
*/ |
121
|
2 |
|
public function asColumn(int $column = 0): ResultSetInterface |
122
|
|
|
{ |
123
|
|
|
/** @var ArrayResultSet<mixed> $this */ |
124
|
2 |
|
$this->strategy = new ColumnArrayFetch($column); |
125
|
|
|
|
126
|
2 |
|
return $this; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* {@inheritdoc} |
131
|
|
|
*/ |
132
|
26 |
|
public function all(): array |
133
|
|
|
{ |
134
|
26 |
|
return $this->strategy->all($this->getArrayCopy()); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* {@inheritdoc} |
139
|
|
|
*/ |
140
|
|
|
#[\ReturnTypeWillChange] |
141
|
15 |
|
public function current() |
142
|
|
|
{ |
143
|
15 |
|
$value = parent::current(); |
144
|
|
|
|
145
|
15 |
|
if ($value === null) { |
146
|
3 |
|
return false; |
147
|
|
|
} |
148
|
|
|
|
149
|
15 |
|
return $this->strategy->one($value); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* {@inheritdoc} |
154
|
|
|
*/ |
155
|
12 |
|
public function rewind(): void |
156
|
|
|
{ |
157
|
12 |
|
parent::rewind(); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* {@inheritdoc} |
162
|
|
|
*/ |
163
|
1 |
|
public function count(): int |
164
|
|
|
{ |
165
|
1 |
|
return parent::count(); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* {@inheritdoc} |
170
|
|
|
*/ |
171
|
1 |
|
public function isRead(): bool |
172
|
|
|
{ |
173
|
1 |
|
return true; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* {@inheritdoc} |
178
|
|
|
*/ |
179
|
1 |
|
public function isWrite(): bool |
180
|
|
|
{ |
181
|
1 |
|
return false; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* {@inheritdoc} |
186
|
|
|
*/ |
187
|
1 |
|
public function hasWrite(): bool |
188
|
|
|
{ |
189
|
1 |
|
return false; |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
|
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