/** * Adds a leaf to the branch tree * * @param Branch $branch */ public function addLeaf(Branch $branch) { if (isset($this->branchMap[$branch->getUniqueId()])) { $branchNode = $this->branchMap[$branch->getUniqueId()]; } else { $branchNode = new BranchGraphNode($branch); } $branchNode->increase(); $tempBranch = $branch->getParentBranch(); while ($tempBranch) { if (isset($this->branchMap[$tempBranch->getUniqueId()])) { $parentBranchNode = $this->branchMap[$tempBranch->getUniqueId()]; } else { $parentBranchNode = new BranchGraphNode($tempBranch); $this->branchMap[$tempBranch->getUniqueId()] = $parentBranchNode; } $parentBranchNode->insert($branchNode); $branchNode = $parentBranchNode; $tempBranch = $tempBranch->getParentBranch(); if (!$tempBranch) { $this->root = $parentBranchNode; } } }
/** * Removes a branch from the branch manager * * @param Branch $branch */ public function removeBranch(Branch $branch) { $parentBranch = $branch->getParentBranch(); $this->currentBranch = $parentBranch; $this->level--; }