@@ -98,6 +98,7 @@ public function countChildren(): int
9898 *
9999 * @throws ChildNotFoundException
100100 * @throws CircularException
101+ * @throws LogicalException
101102 */
102103 public function addChild (AbstractNode $ child , int $ before = -1 ): bool
103104 {
@@ -158,6 +159,10 @@ public function addChild(AbstractNode $child, int $before = -1): bool
158159
159160 // add the child
160161 $ 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+ }
161166 $ this ->children = $ combination ;
162167
163168 // tell child I am the new parent
@@ -300,6 +305,8 @@ public function isChild(int $id): bool
300305 /**
301306 * Removes the child with id $childId and replace it with the new child
302307 * $newChild.
308+ *
309+ * @throws LogicalException
303310 */
304311 public function replaceChild (int $ childId , AbstractNode $ newChild ): void
305312 {
@@ -312,6 +319,10 @@ public function replaceChild(int $childId, AbstractNode $newChild): void
312319 $ index = \array_search ($ childId , $ keys , true );
313320 $ keys [$ index ] = $ newChild ->id ();
314321 $ 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+ }
315326 $ this ->children = $ combination ;
316327 $ this ->children [$ newChild ->id ()] = [
317328 'prev ' => $ oldChild ['prev ' ],
0 commit comments