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

InvalidFieldQuery   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 1
A fieldsNotAllowed() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Spatie\QueryBuilder\Exceptions;
4
5
use Illuminate\Http\Response;
6
use Illuminate\Support\Collection;
7
8 View Code Duplication
class InvalidFieldQuery extends InvalidQuery
0 ignored issues
show
Duplication introduced by Te7a-Houdini
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
{
10
    /** @var \Illuminate\Support\Collection */
11
    public $unknownFields;
12
13
    /** @var \Illuminate\Support\Collection */
14
    public $allowedFields;
15
16
    public function __construct(Collection $unknownFields, Collection $allowedFields)
17
    {
18
        $this->unknownFields = $unknownFields;
19
        $this->allowedFields = $allowedFields;
20
21
        $unknownFields = $unknownFields->implode(', ');
22
        $allowedFields = $allowedFields->implode(', ');
23
        $message = "Requested field(s) `{$unknownFields}` are not allowed. Allowed field(s) are `{$allowedFields}`.";
24
25
        parent::__construct(Response::HTTP_BAD_REQUEST, $message);
26
    }
27
28
    public static function fieldsNotAllowed(Collection $unknownFields, Collection $allowedFields)
0 ignored issues
show
Unused Code introduced by Te7a-Houdini
The parameter $unknownFields 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 Te7a-Houdini
The parameter $allowedFields 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 Te7a-Houdini
The call to InvalidFieldQuery::__construct() misses a required argument $allowedFields.

This check looks for function calls that miss required arguments.

Loading history...
Documentation introduced by Te7a-Houdini
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