Completed
Pull Request — master (#18)
by
unknown
04:30
created

InvalidIncludeQuery   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 35
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A includesNotAllowed() 0 4 1
A getUnknownIncludes() 0 4 1
A getAllowedIncludes() 0 4 1
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
    private $unknownIncludes;
12
13
    /** @var \Illuminate\Support\Collection */
14
    private $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
        $allowedIncludes = $allowedIncludes->implode(', ');
23
        $message = "Given include(s) `{$unknownIncludes}` are not allowed. Allowed includes are `{$allowedIncludes}`.";
24
25
        parent::__construct(Response::HTTP_BAD_REQUEST, $message);
26
    }
27
28
    public static function includesNotAllowed(Collection $unknownIncludes, Collection $allowedIncludes)
0 ignored issues
show
Unused Code introduced by
The parameter $unknownIncludes is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $allowedIncludes is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
    {
30
        return new static(...func_get_args());
0 ignored issues
show
Bug introduced by
The call to InvalidIncludeQuery::__construct() misses a required argument $allowedIncludes.

This check looks for function calls that miss required arguments.

Loading history...
Documentation introduced by
func_get_args() is of type array, but the function expects a 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);
Loading history...
31
    }
32
33
    public function getUnknownIncludes(): Collection
34
    {
35
        return $this->unknownIncludes;
36
    }
37
38
    public function getAllowedIncludes(): Collection
39
    {
40
        return $this->allowedIncludes;
41
    }
42
}
43