src/Database/NestedSet/Builder.php
protected static function reorderNodes(array &$dictionary, &$fixed,
        $parentId = null, $cut = 1
    )
    {
        if (!isset($dictionary[$parentId])) {
            return $cut;
        }

        /** @var ModelBase|NestedTree $model */
        foreach ($dictionary[$parentId] as $model) {
            $lft = $cut;

            $cut = self::reorderNodes($dictionary,
                $fixed,
                $model->getKey(),
                $cut + 1);

            $rgt = $cut;

            if ($model->rawNode($lft, $rgt, $parentId)->isDirty()) {
                $model->save();

                $fixed++;
            }

            ++$cut;
        }

        unset($dictionary[$parentId]);

        return $cut;
    }
protected static function reorderNodes(array &$dictionary, &$fixed,
        $parentId = null, $cut = 1
    )
    {
        if (!isset($dictionary[$parentId])) {
            return $cut;
        }

        /** @var ModelBase|NestedTree $model */
        foreach ($dictionary[$parentId] as $model) {
            $lft = $cut;

            $cut = self::reorderNodes($dictionary,
                $fixed,
                $model->getKey(),
                $cut + 1);

            $rgt = $cut;

            if ($model->rawNode($lft, $rgt, $parentId)->isDirty()) {
                $model->save();

                $fixed++;
            }

            ++$cut;
        }

        unset($dictionary[$parentId]);

        return $cut;
    }
@param array $dictionary
@param int $fixed
@param $parentId
@param int $cut

@return int