@@ -108,90 +108,84 @@ public static function apiDocAllAllowedFilters(): array
108108 );
109109 }
110110
111+ public static function apiDocNewControllerInstance (): static
112+ {
113+ return app (static ::class);
114+ }
115+
111116 public static function apiDocDefaultSort (): string
112117 {
113- /** @var self $new_instance */
114- $ new_instance = app (static ::class);
118+ $ new_instance = static ::apiDocNewControllerInstance ();
115119
116120 return $ new_instance ->getDefaultSort ();
117121 }
118122
119123 public static function apiDocAllowedFilters (): array
120124 {
121- /** @var self $new_instance */
122- $ new_instance = app (static ::class);
125+ $ new_instance = static ::apiDocNewControllerInstance ();
123126
124127 return $ new_instance ->getAllowedFilters ();
125128 }
126129
127130 public static function apiDocAllowedIncludes (): array
128131 {
129- /** @var self $new_instance */
130- $ new_instance = app (static ::class);
132+ $ new_instance = static ::apiDocNewControllerInstance ();
131133
132134 return $ new_instance ->getAllowedIncludes ();
133135 }
134136
135137 public static function apiDocIndexAllowedFields (): array
136138 {
137- /** @var self $new_instance */
138- $ new_instance = app (static ::class);
139+ $ new_instance = static ::apiDocNewControllerInstance ();
139140
140141 return array_merge ($ new_instance ->getIndexAllowedFields (), $ new_instance ->getAllowedAppendAttributes ());
141142 }
142143
143144 public static function apiDocIndexAllowedAppends (): array
144145 {
145- /** @var self $new_instance */
146- $ new_instance = app (static ::class);
146+ $ new_instance = static ::apiDocNewControllerInstance ();
147147
148148 return $ new_instance ->getAllowedAppendAttributes ();
149149 }
150150
151151 public static function apiDocShowAllowedFields (): array
152152 {
153- /** @var self $new_instance */
154- $ new_instance = app (static ::class);
153+ $ new_instance = static ::apiDocNewControllerInstance ();
155154
156155 return array_merge ($ new_instance ->getAllowedFields (), $ new_instance ->getShowAllowedAppendAttributes ());
157156 }
158157
159158 public static function apiDocShowAllowedAppends (): array
160159 {
161- /** @var self $new_instance */
162- $ new_instance = app (static ::class);
160+ $ new_instance = static ::apiDocNewControllerInstance ();
163161
164162 return $ new_instance ->getShowAllowedAppendAttributes ();
165163 }
166164
167165 public static function apiDocAllowedSorts (): array
168166 {
169- /** @var self $new_instance */
170- $ new_instance = app (static ::class);
167+ $ new_instance = static ::apiDocNewControllerInstance ();
171168
172169 return $ new_instance ->getAllowedSorts ();
173170 }
174171
175172 public static function apiDocDefaultPerPage (): int
176173 {
177- /** @var self $new_instance */
178- $ new_instance = app (static ::class);
174+ $ new_instance = static ::apiDocNewControllerInstance ();
179175
180176 return $ new_instance ->getDefaultPerPage ();
181177 }
182178
183179 public static function apiDocMaxPerPage (): int
184180 {
185- /** @var self $new_instance */
186- $ new_instance = app (static ::class);
181+ $ new_instance = static ::apiDocNewControllerInstance ();
187182
188183 return $ new_instance ->getMaxPerPage ();
189184 }
190185
191186 public static function apiDocAllowUnlimitedResultsPerPage (): bool
192187 {
193- /** @var self $new_instance */
194- $ new_instance = app (static ::class);
188+ $ new_instance = static ::apiDocNewControllerInstance ();
195189
196190 return $ new_instance ->allowUnlimitedResultsPerPage ();
197191 }
@@ -221,8 +215,8 @@ public static function apiDocGenerateFieldsMetadata(array $fields): array
221215
222216 public static function apiDefaultSortsDescription (): string
223217 {
224- return 'Which fields to sort the results by. ' .
225- '<br>To sort in descending order, append a `-` to the field name, e.g. `?sort=-created_at`. ' .
218+ return 'Which fields to sort the results by. ' .
219+ '<br>To sort in descending order, append a `-` to the field name, e.g. `?sort=-created_at`. ' .
226220 '<br>To sort by multiple fields, provide a comma-separated list, e.g. `?sort=id,-created_at`. ' ;
227221 }
228222
@@ -236,7 +230,7 @@ public static function apiDocGenerateSortsMetadata(array $sorts, string $default
236230 return [
237231 'type ' => 'string ' ,
238232 'description ' => static ::apiSortsDescription () .
239- '<br><br>**Allowed sorts:** ' . "\n" . implode ("\n" , array_map (fn ($ field ) => "- ` $ field` " , $ sorts )) . "\n\n" .
233+ '<br><br>**Allowed sorts:** ' . "\n" . implode ("\n" , array_map (fn ($ field ) => "- ` $ field` " , $ sorts )) . "\n\n" .
240234 '<br>**Default sort:** ' . ($ default_sort ? '` ' . $ default_sort . '` ' : 'None ' ),
241235 'enum ' => static ::apiDocAllowedSorts (),
242236 'example ' => static ::apiDocDefaultSort (),
@@ -294,8 +288,8 @@ public static function apiDocGeneratePerPageMetadata(): array
294288 {
295289 return [
296290 'type ' => 'integer ' ,
297- 'description ' => 'How many results to return per page. ' .
298- (static ::apiDocAllowUnlimitedResultsPerPage () ? '<br></br>To return all results, set `per_page` to `-1` ' : '' ).
291+ 'description ' => 'How many results to return per page. ' .
292+ (static ::apiDocAllowUnlimitedResultsPerPage () ? '<br></br>To return all results, set `per_page` to `-1` ' : '' ) .
299293 '<br>**Max per page:** ' . static ::apiDocMaxPerPage () .
300294 '<br>**Default per page:** ' . static ::apiDocDefaultPerPage (),
301295 'example ' => static ::apiDocDefaultPerPage (),
@@ -306,16 +300,16 @@ public static function apiDocGeneratePageMetadata(): array
306300 {
307301 return [
308302 'type ' => 'integer ' ,
309- 'description ' => 'For paginated results, which page to return. ' ,
303+ 'description ' => 'For paginated results, which page to return. ' ,
310304 'example ' => 1 ,
311305 ];
312306 }
313307
314308 public static function apiDocGenerateFilterMetadata (
315- string $ filter_name ,
309+ string $ filter_name ,
316310 string |AllowedFilter $ filter ,
317- string $ singular_resource_name ,
318- array $ metadata = [],
311+ string $ singular_resource_name ,
312+ array $ metadata = [],
319313 ): array
320314 {
321315 $ filter_title = Str::of ($ filter_name )
@@ -327,20 +321,20 @@ public static function apiDocGenerateFilterMetadata(
327321
328322 return array_merge ([
329323 'type ' => 'string ' ,
330- 'description ' => is_string ($ filter ) ? 'Filter by the ' . Str::lower ($ filter_title ) . ' of the ' . $ singular_resource_name : 'Apply the ' . Str::lower ($ filter_title ) . ' filter ' ,
324+ 'description ' => is_string ($ filter ) ? 'Filter by the ' . Str::lower ($ filter_title ) . ' of the ' . $ singular_resource_name : 'Apply the ' . Str::lower ($ filter_title ) . ' filter ' ,
331325 ], $ metadata );
332326 }
333327
334328
335329 public static function apiDocDefaultQueryParameters (
336- array $ fields = [],
337- array $ sorts = [],
330+ array $ fields = [],
331+ array $ sorts = [],
338332 string $ default_sort = '' ,
339- array $ appends = [],
340- array $ includes = [],
341- array $ filters = [],
342- array $ filter_metadata = [],
343- bool $ include_pagination = false
333+ array $ appends = [],
334+ array $ includes = [],
335+ array $ filters = [],
336+ array $ filter_metadata = [],
337+ bool $ include_pagination = false
344338 ): array
345339 {
346340 $ params = [];
@@ -379,7 +373,7 @@ public static function apiDocDefaultQueryParameters(
379373 $ filter_name = $ filter ->getName ();
380374 }
381375
382- if (! $ filter_name ) {
376+ if (!$ filter_name ) {
383377 continue ;
384378 }
385379
0 commit comments