@@ -179,7 +179,7 @@ public function setDefinition(string $fqn, Definition $definition)
179
179
public function removeDefinition (string $ fqn )
180
180
{
181
181
$ parts = $ this ->splitFqn ($ fqn );
182
- $ this ->removeIndexedDefinition (0 , $ parts , $ this ->definitions );
182
+ $ this ->removeIndexedDefinition (0 , $ parts , $ this ->definitions , $ this -> definitions );
183
183
184
184
unset($ this ->references [$ fqn ]);
185
185
}
@@ -417,24 +417,19 @@ private function indexDefinition(int $level, array $parts, array &$storage, Defi
417
417
* @param array &$storage The current array in which to remove data
418
418
* @param array &$rootStorage The root storage array
419
419
*/
420
- private function removeIndexedDefinition (int $ level , array $ parts , array &$ storage , &$ rootStorage )
420
+ private function removeIndexedDefinition (int $ level , array $ parts , array &$ storage , array &$ rootStorage )
421
421
{
422
422
$ part = $ parts [$ level ];
423
423
424
424
if ($ level + 1 === count ($ parts )) {
425
- if (isset ($ storage [$ part ]) && count ( $ storage [ $ part ]) < 2 ) {
425
+ if (isset ($ storage [$ part ])) {
426
426
unset($ storage [$ part ]);
427
427
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 ) ;
432
432
}
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 );
438
433
}
439
434
} else {
440
435
$ this ->removeIndexedDefinition ($ level + 1 , $ parts , $ storage [$ part ], $ rootStorage );
0 commit comments