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 InvalidIncludeQuery extends InvalidQuery
{
/** @var \Illuminate\Support\Collection */
public $unknownIncludes;
public $allowedIncludes;
public function __construct(Collection $unknownIncludes, Collection $allowedIncludes)
$this->unknownIncludes = $unknownIncludes;
$this->allowedIncludes = $allowedIncludes;
$unknownIncludes = $unknownIncludes->implode(', ');
$message = "Requested include(s) `{$unknownIncludes}` are not allowed. ";
if ($allowedIncludes->count()) {
$allowedIncludes = $allowedIncludes->implode(', ');
$message .= "Allowed include(s) are `{$allowedIncludes}`.";
} else {
$message .= 'There are no allowed includes.';
}
parent::__construct(Response::HTTP_BAD_REQUEST, $message);
public static function includesNotAllowed(Collection $unknownIncludes, Collection $allowedIncludes)
$unknownIncludes
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.
$allowedIncludes
return new static(...func_get_args());
InvalidIncludeQuery::__construct()
This check looks for function calls that miss required arguments.
func_get_args()
array
object<Illuminate\Support\Collection>
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);
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.