private function findOrCreateChild($tree, $id)
    {
        /* @var NodeInterface $node */
        foreach ($tree->getChildren() as $node) {
            if ($id && $node->getId() == $id) {
                return $node;
            }
        }

        $nodeClass = get_class($tree);
        $node = new $nodeClass();
        $tree->addChild($node);

        return $node;
    }