1 | <?php |
||
12 | abstract class JsonApiController extends Controller |
||
13 | { |
||
14 | use JsonApiErrors; |
||
15 | |||
16 | /** |
||
17 | * Return the Eloquent Model for the resource. |
||
18 | * |
||
19 | * @return Model |
||
20 | */ |
||
21 | abstract protected function getModel(); |
||
22 | |||
23 | /** |
||
24 | * Return the type name of the resource. |
||
25 | * |
||
26 | * @return string |
||
27 | */ |
||
28 | protected function getModelType() |
||
32 | |||
33 | /** |
||
34 | * Return a listing of the resource. |
||
35 | * |
||
36 | * @param Request $request |
||
37 | * |
||
38 | * @return JsonApiResponse |
||
39 | */ |
||
40 | public function indexAction(Request $request) |
||
47 | |||
48 | /** |
||
49 | * Store a new record. |
||
50 | * |
||
51 | * @param Request $request |
||
52 | * |
||
53 | * @return JsonApiResponse |
||
54 | */ |
||
55 | public function storeAction(Request $request) |
||
61 | |||
62 | /** |
||
63 | * Return a specified record. |
||
64 | * |
||
65 | * @param Request $request |
||
66 | * @param Model|int $record |
||
67 | * |
||
68 | * @return JsonApiResponse |
||
69 | */ |
||
70 | public function showAction(Request $request, $record) |
||
77 | |||
78 | /** |
||
79 | * Update a specified record. |
||
80 | * |
||
81 | * @param Request $request |
||
82 | * @param Model|int $record |
||
83 | * |
||
84 | * @return JsonApiResponse |
||
85 | */ |
||
86 | public function updateAction(Request $request, $record) |
||
93 | |||
94 | /** |
||
95 | * Destroy a specified record. |
||
96 | * |
||
97 | * @param Request $request |
||
98 | * @param Model|int $record |
||
99 | * |
||
100 | * @return JsonApiResponse |
||
101 | */ |
||
102 | public function destroyAction(Request $request, $record) |
||
109 | |||
110 | /** |
||
111 | * Return an instance of the resource by primary key. |
||
112 | * |
||
113 | * @param int $key |
||
114 | * |
||
115 | * @throws \Illuminate\Database\Eloquent\ModelNotFoundException |
||
116 | * |
||
117 | * @return Model |
||
118 | */ |
||
119 | protected function findModelInstance($key) |
||
123 | |||
124 | /** |
||
125 | * Return any JSON API resource parameters from a request. |
||
126 | * |
||
127 | * @param Request $request |
||
128 | * |
||
129 | * @return array |
||
130 | */ |
||
131 | protected function getRequestParameters($request) |
||
138 | |||
139 | /** |
||
140 | * Return any comma separated values in a request query field as an array. |
||
141 | * |
||
142 | * @param Request $request |
||
143 | * @param string $key |
||
144 | * |
||
145 | * @return array |
||
146 | */ |
||
147 | protected function getRequestQuerySet($request, $key) |
||
151 | |||
152 | /** |
||
153 | * Transform a set of models into a JSON API collection. |
||
154 | * |
||
155 | * @param \Illuminate\Support\Collection $records |
||
156 | * @param array $fields |
||
157 | * |
||
158 | * @return array |
||
159 | */ |
||
160 | protected function transformCollection($records, array $fields = []) |
||
170 | |||
171 | /** |
||
172 | * Transform a model instance into a JSON API object. |
||
173 | * |
||
174 | * @param Model $record |
||
175 | * @param array|null $fields Field names of attributes to limit to |
||
176 | * @param array|null $include Relations to include |
||
177 | * |
||
178 | * @return array |
||
179 | */ |
||
180 | protected function transformRecord($record, array $fields = [], array $include = []) |
||
221 | } |
||
222 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.