protected function sortChildTree(&$tree)
    {
        /** @var AbstractCategoryDocument $node */
        if (is_array($tree)) {
            uasort($tree, [$this, 'sortNodes']);
            foreach ($tree as $node) {
                $children = $node->getChildren();
                if ($children) {
                    $this->sortChildTree($children);
                    $node->setChildren($children);
                }
            }
        } else {
            $tree->uasort([$this, 'sortNodes']);
            $tree->rewind();
            foreach ($tree as $node) {
                $children = $node->getChildren();
                if ($children) {
                    $this->sortChildTree($children);
                    $node->setChildren($children);
                }
            }
        }
    }