Issues (115)

src/helpers.php (7 issues)

1
<?php
2
3
use Illuminate\Http\Request;
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;
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
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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)
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
133
    {
134
        if (is_null($request)) {
135
            $request = request();
136
        }
137
        $service = resolve($serviceName);
138
        $service->parseRequest($request, false, ...$args);
139
140
        return $service;
141
    }
142
}
143