Sulu\Component\Util\SuluNodeHelper::getSiblingNode PHP Method

getSiblingNode() private method

Return either the next or previous sibling of the given node according to the $previous flag.
private getSiblingNode ( PHPCR\NodeInterface $node, boolean $previous = false ) : PHPCR\NodeInterface | null
$node PHPCR\NodeInterface
$previous boolean
return PHPCR\NodeInterface | null
    private function getSiblingNode(NodeInterface $node, $previous = false)
    {
        $parentNode = $node->getParent();
        $children = $parentNode->getNodes();
        $previousNode = null;
        while ($child = current($children)) {
            if ($child->getPath() === $node->getPath()) {
                return $previous ? $previousNode : next($children);
            }
            $previousNode = $child;
            next($children);
        }
        throw new \RuntimeException(sprintf('Could not find node with path "%s" as a child of "%s". This should not happen', $node->getPath(), $parentNode->getPath()));
    }