for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Spatie\QueryBuilder\Exceptions;
use Illuminate\Http\Response;
use Illuminate\Support\Collection;
class InvalidSortQuery extends InvalidQuery
{
/** @var string */
protected $unknownSort;
/** @var \Illuminate\Support\Collection */
protected $allowedSorts;
public function __construct(string $unknownSort, Collection $allowedSorts)
$this->unknownSort = $unknownSort;
$this->allowedSorts = $allowedSorts;
$allowedSorts = $allowedSorts->implode(', ');
$message = "Given sort `{$this->unknownSort}` is not allowed. Allowed sorts are `{$allowedSorts}`.";
parent::__construct(Response::HTTP_BAD_REQUEST, $message);
}
public static function sortsNotAllowed(string $unknownSort, Collection $allowedSorts)
$unknownSort
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.
$allowedSorts
return new static(...func_get_args());
InvalidSortQuery::__construct()
This check looks for function calls that miss required arguments.
func_get_args()
array
string
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example:
function acceptsInteger($int) { } $x = '123'; // string "123" // Instead of acceptsInteger($x); // we recommend to use acceptsInteger((integer) $x);
public function getUnknownSort(): string
return $this->unknownSort;
public function getAllowedSorts(): Collection
return $this->allowedSorts;
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.