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 | View Code Duplication | class InvalidSortQuery extends InvalidQuery |
|
0 ignored issues
–
show
|
|||
9 | { |
||
10 | /** @var \Illuminate\Support\Collection */ |
||
11 | public $unknownSorts; |
||
12 | |||
13 | /** @var \Illuminate\Support\Collection */ |
||
14 | public $allowedSorts; |
||
15 | |||
16 | public function __construct(Collection $unknownSorts, Collection $allowedSorts) |
||
17 | { |
||
18 | $this->unknownSorts = $unknownSorts; |
||
19 | $this->allowedSorts = $allowedSorts; |
||
20 | |||
21 | $allowedSorts = $allowedSorts->implode(', '); |
||
22 | $unknownSorts = $unknownSorts->implode(', '); |
||
23 | $message = "Requested sort(s) `{$unknownSorts}` is not allowed. Allowed sort(s) are `{$allowedSorts}`."; |
||
24 | |||
25 | parent::__construct(Response::HTTP_BAD_REQUEST, $message); |
||
26 | } |
||
27 | |||
28 | public static function sortsNotAllowed(Collection $unknownSorts, Collection $allowedSorts) |
||
29 | { |
||
30 | return new static(...func_get_args()); |
||
31 | } |
||
32 | } |
||
33 |
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.