protected function sortNodesByIndex(array $nodes)
    {
        usort($nodes, function (NodeData $node1, NodeData $node2) {
            if ($node1->getIndex() < $node2->getIndex()) {
                return -1;
            } elseif ($node1->getIndex() > $node2->getIndex()) {
                return 1;
            } else {
                return strcmp($node1->getIdentifier(), $node2->getIdentifier());
            }
        });

        return $nodes;
    }