Completed
Push — master ( 4330e9...dd81e9 )
by Freek
01:42
created

InvalidQuery   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 58.06 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 18
loc 31
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A filtersNotAllowed() 9 9 1
A sortsNotAllowed() 0 8 1
A includesNotAllowed() 9 9 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
use Symfony\Component\HttpKernel\Exception\HttpException;
8
9
class InvalidQuery extends HttpException
10
{
11 View Code Duplication
    public static function filtersNotAllowed(Collection $unknownFilters, Collection $allowedFilters)
0 ignored issues
show
Duplication introduced by
This method 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...
12
    {
13
        $unknownFilters = $unknownFilters->implode(', ');
14
        $allowedFilters = $allowedFilters->implode(', ');
15
16
        $message = "Given filter(s) `{$unknownFilters}` are not allowed. Allowed filters are `{$allowedFilters}`.";
17
18
        return new static(Response::HTTP_BAD_REQUEST, $message);
19
    }
20
21
    public static function sortsNotAllowed(string $unknownSort, Collection $allowedSorts)
22
    {
23
        $allowedSorts = $allowedSorts->implode(', ');
24
25
        $message = "Given sort `{$unknownSort}` is not allowed. Allowed sorts are `{$allowedSorts}`.";
26
27
        return new static(Response::HTTP_BAD_REQUEST, $message);
28
    }
29
30 View Code Duplication
    public static function includesNotAllowed(Collection $unknownIncludes, Collection $allowedIncludes)
0 ignored issues
show
Duplication introduced by
This method 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...
31
    {
32
        $unknownIncludes = $unknownIncludes->implode(', ');
33
        $allowedIncludes = $allowedIncludes->implode(', ');
34
35
        $message = "Given include(s) `{$unknownIncludes}` are not allowed. Allowed includes are `{$allowedIncludes}`.";
36
37
        return new static(Response::HTTP_BAD_REQUEST, $message);
38
    }
39
}
40