1
0
Fork 0

fix definition removal

pull/451/head
Nicolas MURE 2017-11-19 16:34:51 +01:00
parent b03950cb53
commit 97ec127312
No known key found for this signature in database
GPG Key ID: E5B036F9145C4CAA
1 changed files with 7 additions and 12 deletions

View File

@ -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);