fix definition removal
parent
b03950cb53
commit
97ec127312
|
@ -179,7 +179,7 @@ class Index implements ReadableIndex, \Serializable
|
||||||
public function removeDefinition(string $fqn)
|
public function removeDefinition(string $fqn)
|
||||||
{
|
{
|
||||||
$parts = $this->splitFqn($fqn);
|
$parts = $this->splitFqn($fqn);
|
||||||
$this->removeIndexedDefinition(0, $parts, $this->definitions);
|
$this->removeIndexedDefinition(0, $parts, $this->definitions, $this->definitions);
|
||||||
|
|
||||||
unset($this->references[$fqn]);
|
unset($this->references[$fqn]);
|
||||||
}
|
}
|
||||||
|
@ -417,24 +417,19 @@ class Index implements ReadableIndex, \Serializable
|
||||||
* @param array &$storage The current array in which to remove data
|
* @param array &$storage The current array in which to remove data
|
||||||
* @param array &$rootStorage The root storage array
|
* @param array &$rootStorage The root storage array
|
||||||
*/
|
*/
|
||||||
private function removeIndexedDefinition(int $level, array $parts, array &$storage, &$rootStorage)
|
private function removeIndexedDefinition(int $level, array $parts, array &$storage, array &$rootStorage)
|
||||||
{
|
{
|
||||||
$part = $parts[$level];
|
$part = $parts[$level];
|
||||||
|
|
||||||
if ($level + 1 === count($parts)) {
|
if ($level + 1 === count($parts)) {
|
||||||
if (isset($storage[$part]) && count($storage[$part]) < 2) {
|
if (isset($storage[$part])) {
|
||||||
unset($storage[$part]);
|
unset($storage[$part]);
|
||||||
|
|
||||||
if (0 === $level) {
|
if (0 === count($storage)) {
|
||||||
// we're at root level, no need to check for parents
|
// parse again the definition tree to remove the parent
|
||||||
// w/o children
|
// when it has no more children
|
||||||
return;
|
$this->removeIndexedDefinition(0, array_slice($parts, 0, $level), $rootStorage, $rootStorage);
|
||||||
}
|
}
|
||||||
|
|
||||||
array_pop($parts);
|
|
||||||
// parse again the definition tree to see if the parent
|
|
||||||
// can be removed too if it has no more children
|
|
||||||
$this->removeIndexedDefinition(0, $parts, $rootStorage, $rootStorage);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->removeIndexedDefinition($level + 1, $parts, $storage[$part], $rootStorage);
|
$this->removeIndexedDefinition($level + 1, $parts, $storage[$part], $rootStorage);
|
||||||
|
|
Loading…
Reference in New Issue