1 | <?php |
||||||
2 | |||||||
3 | use Illuminate\Http\Request; |
||||||
0 ignored issues
–
show
|
|||||||
4 | use Illuminate\Support\Collection; |
||||||
5 | use Illuminate\Support\Str; |
||||||
6 | |||||||
7 | Request::macro( |
||||||
0 ignored issues
–
show
The method
macro() does not exist on Illuminate\Http\Request .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
8 | 'getIncludes', |
||||||
9 | function (): Collection { |
||||||
10 | $includeName = config('query-builder.parameters.include'); |
||||||
11 | |||||||
12 | return collect(explode(',', $this->query($includeName, null)))->filter() |
||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||||
13 | ->map([Str::class, 'camel']) |
||||||
14 | ->map(function (string $include) { |
||||||
15 | return collect(explode('.', $include)); |
||||||
16 | }); |
||||||
17 | } |
||||||
18 | ); |
||||||
19 | |||||||
20 | Request::macro( |
||||||
21 | 'getFilters', |
||||||
22 | function (): Collection { |
||||||
23 | $filterName = config('query-builder.parameters.filter'); |
||||||
24 | |||||||
25 | return collect($this->query($filterName, null))->filter(); |
||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||||
26 | } |
||||||
27 | ); |
||||||
28 | |||||||
29 | Request::macro( |
||||||
30 | 'getSorts', |
||||||
31 | function (): Collection { |
||||||
32 | $sortName = config('query-builder.parameters.sort'); |
||||||
33 | $sortQuery = $this->query($sortName, null); |
||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||||
34 | |||||||
35 | $col = collect(explode(',', $sortQuery)) |
||||||
36 | ->filter() |
||||||
37 | ->map(function ($item, $key) { |
||||||
0 ignored issues
–
show
The parameter
$key is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||
38 | // Clean sort parameter |
||||||
39 | return in_array($item[0], ['+', '-']) ? $item : "+{$item}"; |
||||||
40 | }); |
||||||
41 | |||||||
42 | |||||||
43 | // For spatie/laravel-query-builder |
||||||
44 | if (!is_null($sortQuery)) { |
||||||
45 | $this->query->set($sortName, str_replace('+', null, $sortQuery)); |
||||||
46 | } |
||||||
47 | |||||||
48 | return $col; |
||||||
49 | } |
||||||
50 | ); |
||||||
51 | |||||||
52 | Request::macro( |
||||||
53 | 'getFields', |
||||||
54 | function (): Collection { |
||||||
55 | $fieldName = config('query-builder.parameters.fields'); |
||||||
56 | return collect($this->query($fieldName, null))->filter()->map(function ($item) { |
||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||||
57 | return explode(',', $item); |
||||||
58 | }); |
||||||
59 | } |
||||||
60 | ); |
||||||
61 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: