1 | <?php |
||||
2 | |||||
3 | namespace VGirol\JsonApi\Resources; |
||||
4 | |||||
5 | use Illuminate\Support\Facades\Request; |
||||
6 | use Illuminate\Support\Facades\Route; |
||||
7 | |||||
8 | trait CanCreateLink |
||||
9 | { |
||||
10 | /** |
||||
11 | * Undocumented function |
||||
12 | * |
||||
13 | * @param Request $request |
||||
14 | * |
||||
15 | * @return string |
||||
16 | */ |
||||
17 | public function getDocumentSelfLink($request): string |
||||
18 | { |
||||
19 | // $url = rawurldecode($request->fullUrl()); |
||||
20 | // $elements = explode('?', $url); |
||||
21 | // if (count($elements) > 1) { |
||||
22 | // $elements[1] = collect(explode('&', $elements[1])) |
||||
23 | // ->map(function ($item) { |
||||
24 | // return collect(explode('=', $item))->map(function ($item) { |
||||
25 | // return rawurlencode($item); |
||||
26 | // })->join('='); |
||||
27 | // })->join('&'); |
||||
28 | // $url = implode('?', $elements); |
||||
29 | // } |
||||
30 | |||||
31 | // return $url; |
||||
32 | return $request->fullUrl(); |
||||
33 | } |
||||
34 | |||||
35 | /** |
||||
36 | * Undocumented function |
||||
37 | * |
||||
38 | * @param Request $request |
||||
39 | * @param bool $withQuery |
||||
40 | * |
||||
41 | * @return string|null |
||||
42 | */ |
||||
43 | public function getCollectionSelfLink($request, $withQuery = false): ?string |
||||
44 | { |
||||
45 | return $this->getUrl( |
||||
46 | "{$this->aliases->getResourceRoute($request)}.index", |
||||
47 | $withQuery ? $request->query() : [] |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
48 | ); |
||||
49 | } |
||||
50 | |||||
51 | /** |
||||
52 | * Undocumented function |
||||
53 | * |
||||
54 | * @param Request $request |
||||
55 | * @return string|null |
||||
56 | */ |
||||
57 | public function getDocumentRelatedLink($request): ?string |
||||
58 | { |
||||
59 | return $this->getUrl( |
||||
60 | "{$this->aliases->getParentRoute($request)}.related.index", |
||||
61 | [ |
||||
62 | 'parentId' => $request->route('parentId'), |
||||
63 | 'relationship' => $request->route('relationship') |
||||
64 | ] |
||||
65 | ); |
||||
66 | } |
||||
67 | |||||
68 | /** |
||||
69 | * Undocumented function |
||||
70 | * |
||||
71 | * @param string $model |
||||
72 | * |
||||
73 | * @return string |
||||
74 | */ |
||||
75 | public function getResourceSelfLink($model): ?string |
||||
76 | { |
||||
77 | return $this->getUrl( |
||||
78 | "{$this->aliases->getResourceRoute($model)}.show", |
||||
79 | [ |
||||
80 | 'id' => $this->getId() |
||||
0 ignored issues
–
show
It seems like
getId() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
81 | ] |
||||
82 | ); |
||||
83 | } |
||||
84 | |||||
85 | /** |
||||
86 | * Undocumented function |
||||
87 | * |
||||
88 | * @param Model $model Parent model |
||||
0 ignored issues
–
show
The type
VGirol\JsonApi\Resources\Model 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
89 | * @param string $relationshipName |
||||
90 | * |
||||
91 | * @return string|null |
||||
92 | */ |
||||
93 | public function getRelationshipSelfLink($model, string $relationshipName): ?string |
||||
94 | { |
||||
95 | return $this->getUrl( |
||||
96 | "{$this->aliases->getPArentRoute($model)}.relationship.index", |
||||
97 | [ |
||||
98 | 'parentId' => $model->getKey(), |
||||
99 | 'relationship' => $relationshipName |
||||
100 | ] |
||||
101 | ); |
||||
102 | } |
||||
103 | |||||
104 | /** |
||||
105 | * Undocumented function |
||||
106 | * |
||||
107 | * @param Model $model Parent model |
||||
108 | * @param string $relationshipName |
||||
109 | * |
||||
110 | * @return string|null |
||||
111 | */ |
||||
112 | public function getRelationshipRelatedLink($model, string $relationshipName): ?string |
||||
113 | { |
||||
114 | return $this->getUrl( |
||||
115 | "{$this->aliases->getParentRoute($model)}.related.index", |
||||
116 | [ |
||||
117 | 'parentId' => $model->getKey(), |
||||
118 | 'relationship' => $relationshipName |
||||
119 | ] |
||||
120 | ); |
||||
121 | } |
||||
122 | |||||
123 | /** |
||||
124 | * Undocumented function |
||||
125 | * |
||||
126 | * @param string $routeName |
||||
127 | * @param array $params |
||||
128 | * |
||||
129 | * @return string|null |
||||
130 | */ |
||||
131 | private function getUrl(string $routeName, array $params = []): ?string |
||||
132 | { |
||||
133 | return Route::has($routeName) ? route($routeName, $params) : null; |
||||
0 ignored issues
–
show
The method
has() does not exist on Illuminate\Support\Facades\Route .
(
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. ![]() |
|||||
134 | } |
||||
135 | } |
||||
136 |