@@ -98,6 +98,7 @@ public function countChildren(): int
98
98
*
99
99
* @throws ChildNotFoundException
100
100
* @throws CircularException
101
+ * @throws LogicalException
101
102
*/
102
103
public function addChild (AbstractNode $ child , int $ before = -1 ): bool
103
104
{
@@ -158,6 +159,10 @@ public function addChild(AbstractNode $child, int $before = -1): bool
158
159
159
160
// add the child
160
161
$ combination = \array_combine ($ keys , $ children );
162
+ if ($ combination === false ) {
163
+ // The number of elements for each array isn't equal or if the arrays are empty.
164
+ throw new LogicalException ('array combine failed during add child method call. ' );
165
+ }
161
166
$ this ->children = $ combination ;
162
167
163
168
// tell child I am the new parent
@@ -300,6 +305,8 @@ public function isChild(int $id): bool
300
305
/**
301
306
* Removes the child with id $childId and replace it with the new child
302
307
* $newChild.
308
+ *
309
+ * @throws LogicalException
303
310
*/
304
311
public function replaceChild (int $ childId , AbstractNode $ newChild ): void
305
312
{
@@ -312,6 +319,10 @@ public function replaceChild(int $childId, AbstractNode $newChild): void
312
319
$ index = \array_search ($ childId , $ keys , true );
313
320
$ keys [$ index ] = $ newChild ->id ();
314
321
$ combination = \array_combine ($ keys , $ this ->children );
322
+ if ($ combination === false ) {
323
+ // The number of elements for each array isn't equal or if the arrays are empty.
324
+ throw new LogicalException ('array combine failed during replace child method call. ' );
325
+ }
315
326
$ this ->children = $ combination ;
316
327
$ this ->children [$ newChild ->id ()] = [
317
328
'prev ' => $ oldChild ['prev ' ],
0 commit comments