Returns the next highest sort value

@param array $scope Optional conditions
@return int
553826
public function getNextSortValue(array $scope = []): int
    {
        $query = $this->_table->query();
        $scope = Hash::merge($this->getConfig('scope'), $scope);
        if (!empty($scope)) {
            $query->where($scope);
        }
        $query->select([
            'maxSort' => $query->func()->max($this->getConfig('sortField')),
        ]);
        $res = $query->enableHydration(false)->first();
        if (empty($res)) {
            return 1;
        }

        return ($res['maxSort'] + 1);
    }
792143
public static function sortByKey($array, $key, $useDotSyntax = false)
    {
        uasort($array, function ($a, $b) use ($key, $useDotSyntax) {
            $valueA = self::get($a, $key, null, $useDotSyntax);
            $valueB = self::get($b, $key, null, $useDotSyntax);
            if ($valueA == $valueB) {
                return 0;
            }

            return ($valueA < $valueB) ? -1 : 1;
        });

        return $array;
    }
897947
public function getCurrentScope()
    {
        $key = request(Scope::QUERY_NAME);

        return $this->scopes->first(function ($scope) use ($key) {
            return $scope->key == $key;
        });
    }
1254829
public static function sortRecursive($array)
    {
        foreach ($array as &$value) {
            if (is_array($value)) {
                $value = static::sortRecursive($value);
            }
        }

        if (static::isAssoc($array)) {
            ksort($array);
        } else {
            sort($array);
        }

        return $array;
    }
889529
protected function _scope($query)
    {
        $scope = $this->getConfig('scope');

        if (is_array($scope)) {
            return $query->where($scope);
        }
        if (is_callable($scope)) {
            return $scope($query);
        }

        return $query;
    }
402944
public function checkScope($scope)
	{
		if (isset($this->scopes[$scope])) {
			return $this->scopes[$scope];
		}
		
		if (!empty($this->scopes['*'])) {
			return true;
		}
		
		if (!$this->check()) {
			return false;
		}
		
		if ('user' == $this->type) {
			$this->scopes[$scope] = Authorizer::hasScope($scope);
		}
		else {
			$client = $this->client();
			$this->scopes[$scope] = in_array($scope, $client->scopes());
		}
		
		if (!$this->scopes[$scope] && '*' != $scope) {
			$this->scopes[$scope] = $this->checkScope('*');
		}
		
		return $this->scopes[$scope];
	}
264088
public function getMaxSortIndex()
    {
        return (new Query())->from($this->refTableName)->where([$this->refFieldName => $this->itemId])->max($this->sortIndexFieldName);
    }
483122
public static function getGlobalScope($scope)
    {
        if (is_string($scope)) {
            return Arr::get(static::$globalScopes, static::class.'.'.$scope);
        }

        return Arr::get(
            static::$globalScopes, static::class.'.'.get_class($scope)
        );
    }
1048756
public function getOrderOption($sortValue)
    {
        $orders = array();
        if ($sortValue = trim($sortValue)) {
            $lines = array_map('trim', explode("\n", $sortValue));
            foreach ($lines as $line) {
                if (count($values = array_map('trim', explode(',', $line)))) {
                    $column = $values[0];
                    $order = (count($values) > 1) ? strtoupper($values[1]) : null;
                    if (!in_array($order, array('ASC', 'DESC'))) {
                        $order = 'ASC';
                    }
                    $orders[$column] = $order;
                }
            }
        }

        return $orders;
    }
898713
public function rank()
    {
        $eps = pow(2.0, -52.0);
        $tol = max($this->m, $this->n) * $this->s[0] * $eps;
        $r = 0;
        for ($i = 0; $i < count($this->s); ++$i) {
            if ($this->s[$i] > $tol) {
                ++$r;
            }
        }
        return $r;
    }
236260
public static function max($array = false, $decimals = 3) {

        if($array && Validate::isArray($array)) {

            return self::round(max($array), $decimals);
        }

        return false;
    }
671334
public function canAccess(string $scope)
    {
        $scopes = func_get_args();
        $diff = array_diff($scopes, $this->scope);
        return count($diff)>0;
    }
1239507
public function all($scope = null)
    {
        if ($scope === null) {
            return array_values($this->messages);
        }

        $messages = array();
        foreach ($this->messages as $message) {
            if ($message['scope'] === $scope) {
                $messages[] = $message;
            }
        }

        return $messages;
    }
1182805
public function sortingPriority($key)
    {
        $this->bootCanSortMethodsOnce();

        if (!isset($this->sorting[$key])) {
            return 0;
        }

        return array_search($key, array_keys($this->sorting)) + 1;
    }
498270
public function max($collection=null, $iterator=null) {
    list($collection, $iterator) = self::_wrapArgs(func_get_args(), 2);
    
    if(is_null($iterator)) return self::_wrap(max($collection));
    
    $results = array();
    foreach($collection as $k=>$item) {
      $results[$k] = $iterator($item);
    }
    arsort($results);
    $__ = new self;
    $first_key = $__->first(array_keys($results));
    return $collection[$first_key];
  }
18231
public static function sort( &$array, $first = NULL, $last = NULL )
	{
		if( !is_array( $array ) )
			return FALSE;
		if( is_null( $first ) )
			$first = 0;
		if( is_null( $last ) )
			$last = count( $array ) - 1;
		if( $first < $last )
		{
			$middle		= $first + $last;
			$middle		= floor( ( $first + $last ) / 2 );
			$compare	= $array[$middle];
			$left		= $first;
			$right	= $last;
			while( $left <= $right )
			{
				while( $array[$left] < $compare )
					$left++;
				while( $array[$right] > $compare )
					$right--;
				if( $left <= $right )
				{
					self::swap( $array, $left, $right );
					$left++;
					$right--;
				}
			}
			self::sort( $array, $first, $right );
			self::sort( $array, $left, $last );
		}
		return $array;
	}
1100698
public function setScope($scope)
  {
      if (!is_array($scope)) {
          $this->scopes = explode(' ', $scope);
      } else {
          $this->scopes = $scope;
      }

      return $this;
  }