@@ -142,24 +142,37 @@ public function peek(): mixed
142
142
}
143
143
144
144
145
- // -------------------------
146
- // ArrayAccess Interface
147
- // -------------------------
148
-
149
145
/**
150
- * @inheritdoc
146
+ * @param mixed $offset
147
+ * @param mixed $value
148
+ * @return void
151
149
*
152
- * @throws TypeError|OutOfBoundsException if $value is not of the type defined
153
- * with this getEntityType, or f $offset is not an int
150
+ * @throws OutOfBoundsException
154
151
*/
155
- public function offsetSet (mixed $ offset , mixed $ value ): void
152
+ protected function doInsert (mixed $ offset , mixed $ value )
156
153
{
157
- if (!is_null ($ offset ) && !is_int ($ offset )) { // @phpstan-ignore-line
154
+ if (!is_null ($ offset ) && !is_int ($ offset )) {
158
155
throw new OutOfBoundsException (
159
156
"expected integer key for \"offset \", " .
160
- "but got \" $ offset \" ( type: " . (gettype ($ offset )) . " ) "
157
+ "but got type: " . (gettype ($ offset ))
161
158
);
162
159
}
160
+
161
+ if (is_null ($ offset )) {
162
+ $ this ->data [] = $ value ;
163
+ } else {
164
+ $ this ->data [$ offset ] = $ value ;
165
+ }
166
+ }
167
+
168
+ /**
169
+ * @param mixed $value
170
+ * @return bool
171
+ *
172
+ * @throws TypeError
173
+ */
174
+ protected function assertTypeFor (mixed $ value ): bool
175
+ {
163
176
$ entityType = $ this ->getEntityType ();
164
177
165
178
// instanceof has higher precedence, do
@@ -172,14 +185,26 @@ public function offsetSet(mixed $offset, mixed $value): void
172
185
);
173
186
}
174
187
175
- if (is_null ($ offset )) {
176
- $ this ->data [] = $ value ;
177
- } else {
178
- $ this ->data [$ offset ] = $ value ;
179
- }
188
+ return true ;
180
189
}
181
190
182
191
192
+ // -------------------------
193
+ // ArrayAccess Interface
194
+ // -------------------------
195
+
196
+ /**
197
+ * @inheritdoc
198
+ *
199
+ * @throws TypeError|OutOfBoundsException if $value is not of the type defined
200
+ * with this getEntityType, or f $offset is not an int
201
+ */
202
+ public function offsetSet (mixed $ offset , mixed $ value ): void
203
+ {
204
+ $ this ->assertTypeFor ($ value );
205
+ $ this ->doInsert ($ offset , $ value );
206
+ }
207
+
183
208
184
209
/**
185
210
* @inheritdoc
0 commit comments