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()));
}