private function addPathPartToTree(TreeNode $node, RoutePath $path, Route $route, int $index): TreeNode
    {
        $pathNode = $this->pathToNode($path, $route, $index);

        foreach ($node->getChildren() as $child) {
            if ($child->withoutChildren() == $pathNode->withoutChildren()) {
                return $child;
            }
        }

        $node->addChild($pathNode);

        return $pathNode;
    }
private function addPathPartToTree(TreeNode $node, RoutePath $path, Route $route, int $index): TreeNode
    {
        $pathNode = $this->pathToNode($path, $route, $index);

        foreach ($node->getChildren() as $child) {
            if ($child->withoutChildren() == $pathNode->withoutChildren()) {
                return $child;
            }
        }

        $node->addChild($pathNode);

        return $pathNode;
    }
private function addPathPartToTree ( TreeNode $ node , RoutePath $ path , Route $ route , int $ index ) : TreeNode { $ pathNode = $ this -> pathToNode ( $ path , $ route , $ index ) ; foreach ( $ node -> getChildren ( ) as $ child ) { if ( $ child -> withoutChildren ( ) == $ pathNode -> withoutChildren ( ) ) { return $ child ; } } $ node -> addChild ( $ pathNode ) ; return $ pathNode ; }
Adds route path to the given node. Merges with existing one,
if possible, otherwise creates new tree node.

@param TreeNode $node
@param RoutePath $path
@param Route $route
@param int $index
@return TreeNode
Adds route path to the given node . Merges with existing one if possible otherwise creates new tree node .