Completed
Push — master ( 187043...48cde4 )
by
unknown
01:30
created

src/Exceptions/InvalidIncludeQuery.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Spatie\QueryBuilder\Exceptions;
4
5
use Illuminate\Http\Response;
6
use Illuminate\Support\Collection;
7
8
class InvalidIncludeQuery extends InvalidQuery
9
{
10
    /** @var \Illuminate\Support\Collection */
11
    public $unknownIncludes;
12
13
    /** @var \Illuminate\Support\Collection */
14
    public $allowedIncludes;
15
16
    public function __construct(Collection $unknownIncludes, Collection $allowedIncludes)
17
    {
18
        $this->unknownIncludes = $unknownIncludes;
19
        $this->allowedIncludes = $allowedIncludes;
20
21
        $unknownIncludes = $unknownIncludes->implode(', ');
22
23
        $message = "Requested include(s) `{$unknownIncludes}` are not allowed. ";
24
25
        if ($allowedIncludes->count()) {
26
            $allowedIncludes = $allowedIncludes->implode(', ');
27
            $message .= "Allowed include(s) are `{$allowedIncludes}`.";
28
        } else {
29
            $message .= 'There are no allowed includes.';
30
        }
31
32
        parent::__construct(Response::HTTP_BAD_REQUEST, $message);
33
    }
34
35
    public static function includesNotAllowed(Collection $unknownIncludes, Collection $allowedIncludes)
36
    {
37
        return new static(...func_get_args());
0 ignored issues
show
The call to InvalidIncludeQuery::__construct() misses a required argument $allowedIncludes.

This check looks for function calls that miss required arguments.

Loading history...
38
    }
39
}
40