Issues (115)

src/helpers.php (3 issues)

1
<?php
2
3
use Illuminate\Http\Request;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Request. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/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 before OtherDir/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:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
4
use VGirol\JsonApi\Services\AliasesService;
5
use VGirol\JsonApi\Services\ExceptionService;
6
use VGirol\JsonApi\Services\FieldsService;
7
use VGirol\JsonApi\Services\FilterService;
8
use VGirol\JsonApi\Services\IncludeService;
9
use VGirol\JsonApi\Services\ModelService;
10
use VGirol\JsonApi\Services\PaginationService;
11
use VGirol\JsonApi\Services\Service;
0 ignored issues
show
The type VGirol\JsonApi\Services\Service was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use VGirol\JsonApi\Services\SortService;
13
14
if (!function_exists('jsonapiAliases')) {
15
    /**
16
     * Undocumented function
17
     *
18
     * @return AliasesService
19
     */
20
    function jsonapiAliases(): AliasesService
21
    {
22
        return app()->make(AliasesService::class);
23
    }
24
}
25
26
if (!function_exists('jsonapiError')) {
27
    /**
28
     * Undocumented function
29
     *
30
     * @param \Throwable $e
31
     * @param boolean $check
32
     *
33
     * @return ExceptionService
34
     */
35
    function jsonapiError(\Throwable $e = null, $check = true): ExceptionService
36
    {
37
        $service = app()->make(ExceptionService::class);
38
        if (!is_null($e)) {
39
            $service->addException($e, $check);
40
        }
41
42
        return $service;
43
    }
44
}
45
46
if (!function_exists('jsonapiModel')) {
47
    /**
48
     * Undocumented function
49
     *
50
     * @return ModelService
51
     */
52
    function jsonapiModel(): ModelService
53
    {
54
        return app()->make(ModelService::class);
55
    }
56
}
57
58
if (!function_exists('jsonapiFields')) {
59
    /**
60
     * Undocumented function
61
     *
62
     * @param Request $request
63
     * @return FieldsService
64
     */
65
    function jsonapiFields(Request $request = null): FieldsService
66
    {
67
        return jsonapiService(FieldsService::class, $request);
68
    }
69
}
70
71
if (!function_exists('jsonapiFilter')) {
72
    /**
73
     * Undocumented function
74
     *
75
     * @param Request $request
76
     * @return FilterService
77
     */
78
    function jsonapiFilter(Request $request = null): FilterService
79
    {
80
        return jsonapiService(FilterService::class, $request);
81
    }
82
}
83
84
if (!function_exists('jsonapiInclude')) {
85
    /**
86
     * Undocumented function
87
     *
88
     * @param Request $request
89
     * @return IncludeService
90
     */
91
    function jsonapiInclude(Request $request = null): IncludeService
92
    {
93
        return jsonapiService(IncludeService::class, $request);
94
    }
95
}
96
97
if (!function_exists('jsonapiPagination')) {
98
    /**
99
     * Undocumented function
100
     *
101
     * @param Request $request
102
     * @param int|null $totalItem
103
     * @return PaginationService
104
     */
105
    function jsonapiPagination(Request $request = null, $totalItem = null): PaginationService
106
    {
107
        return jsonapiService(PaginationService::class, $request, $totalItem);
108
    }
109
}
110
111
if (!function_exists('jsonapiSort')) {
112
    /**
113
     * Undocumented function
114
     *
115
     * @param Request $request
116
     * @return SortService
117
     */
118
    function jsonapiSort(Request $request = null): SortService
119
    {
120
        return jsonapiService(SortService::class, $request);
121
    }
122
}
123
124
if (!function_exists('jsonapiService')) {
125
    /**
126
     * Undocumented function
127
     *
128
     * @param Request $request
129
     *
130
     * @return Service
131
     */
132
    function jsonapiService(string $serviceName, Request $request = null, ...$args)
133
    {
134
        if (is_null($request)) {
135
            $request = request();
136
        }
137
        $service = resolve($serviceName);
138
        $service->parseRequest($request, false, ...$args);
0 ignored issues
show
The method parseRequest() does not exist on Illuminate\Contracts\Foundation\Application. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

138
        $service->/** @scrutinizer ignore-call */ 
139
                  parseRequest($request, false, ...$args);

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.

Loading history...
139
140
        return $service;
141
    }
142
}
143