@@ -179,7 +179,7 @@ public function setDefinition(string $fqn, Definition $definition)
179179 public function removeDefinition (string $ fqn )
180180 {
181181 $ parts = $ this ->splitFqn ($ fqn );
182- $ this ->removeIndexedDefinition (0 , $ parts , $ this ->definitions );
182+ $ this ->removeIndexedDefinition (0 , $ parts , $ this ->definitions , $ this -> definitions );
183183
184184 unset($ this ->references [$ fqn ]);
185185 }
@@ -417,24 +417,19 @@ private function indexDefinition(int $level, array $parts, array &$storage, Defi
417417 * @param array &$storage The current array in which to remove data
418418 * @param array &$rootStorage The root storage array
419419 */
420- private function removeIndexedDefinition (int $ level , array $ parts , array &$ storage , &$ rootStorage )
420+ private function removeIndexedDefinition (int $ level , array $ parts , array &$ storage , array &$ rootStorage )
421421 {
422422 $ part = $ parts [$ level ];
423423
424424 if ($ level + 1 === count ($ parts )) {
425- if (isset ($ storage [$ part ]) && count ( $ storage [ $ part ]) < 2 ) {
425+ if (isset ($ storage [$ part ])) {
426426 unset($ storage [$ part ]);
427427
428- if (0 === $ level ) {
429- // we're at root level, no need to check for parents
430- // w/o children
431- return ;
428+ if (0 === count ( $ storage ) ) {
429+ // parse again the definition tree to remove the parent
430+ // when it has no more children
431+ $ this -> removeIndexedDefinition ( 0 , array_slice ( $ parts , 0 , $ level ), $ rootStorage , $ rootStorage ) ;
432432 }
433-
434- array_pop ($ parts );
435- // parse again the definition tree to see if the parent
436- // can be removed too if it has no more children
437- $ this ->removeIndexedDefinition (0 , $ parts , $ rootStorage , $ rootStorage );
438433 }
439434 } else {
440435 $ this ->removeIndexedDefinition ($ level + 1 , $ parts , $ storage [$ part ], $ rootStorage );
0 commit comments