Conditions | 1 |
Paths | 1 |
Total Lines | 149 |
Code Lines | 112 |
Lines | 0 |
Ratio | 0 % |
Changes | 12 | ||
Bugs | 4 | Features | 5 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
234 | #[ |
||
235 | Get( |
||
236 | path: "/posts/filters", |
||
237 | operationId: "postGetWithFilter", |
||
238 | description: "Get all posts with pagination (10 items per page by default, page 1 by default) |
||
239 | |||
240 | This API will get records from the database and return them as a paginated list. |
||
241 | The default number of items per page is 10 and the default page number is 1. You can change these values by passing the `per_page` and `page` query parameters. |
||
242 | ", |
||
243 | summary: "Get posts by filter with pagination", |
||
244 | tags: ["Post"], |
||
245 | parameters: [ |
||
246 | new Parameter( |
||
247 | name: 'categories', |
||
248 | description: 'Filter posts by categories IDs', |
||
249 | in: 'query', |
||
250 | required: false, |
||
251 | schema: new Schema( |
||
252 | type: 'array', |
||
253 | items: new Items(description: 'Input the category ID', type: 'integer'), |
||
254 | default: null, |
||
255 | ) |
||
256 | ), |
||
257 | new Parameter( |
||
258 | name: 'categories_exclude', |
||
259 | description: 'Filter posts by excluding specific category IDs.', |
||
260 | in: 'query', |
||
261 | required: false, |
||
262 | schema: new Schema( |
||
263 | type: 'array', |
||
264 | items: new Items(description: 'Input the exclude category ID', type: 'integer'), |
||
265 | default: null |
||
266 | ) |
||
267 | ), |
||
268 | new Parameter( |
||
269 | name: 'exclude', |
||
270 | description: 'Filter posts by excluding specific post IDs.', |
||
271 | in: 'query', |
||
272 | required: false, |
||
273 | schema: new Schema( |
||
274 | type: 'array', |
||
275 | items: new Items(description: 'Input the exclude post ID', type: 'integer'), |
||
276 | default: null |
||
277 | ) |
||
278 | ), |
||
279 | new Parameter( |
||
280 | name: 'author', |
||
281 | description: 'Filter posts by author IDs', |
||
282 | in: 'query', |
||
283 | required: false, |
||
284 | schema: new Schema( |
||
285 | type: 'array', |
||
286 | items: new Items(description: 'Input the author ID', type: 'integer'), |
||
287 | default: null |
||
288 | ) |
||
289 | ), |
||
290 | new Parameter( |
||
291 | name: 'author_exclude', |
||
292 | description: 'Filter posts by excluding specific author IDs.', |
||
293 | in: 'query', |
||
294 | required: false, |
||
295 | schema: new Schema( |
||
296 | type: 'array', |
||
297 | items: new Items(description: 'Input the exclude author ID', type: 'integer'), |
||
298 | default: null |
||
299 | ) |
||
300 | ), |
||
301 | new Parameter( |
||
302 | name: 'featured', |
||
303 | description: 'Filter posts by featured status. Accepts values: |
||
304 | 1 for featured posts |
||
305 | 0 for non-featured posts.', |
||
306 | in: 'query', |
||
307 | required: false, |
||
308 | schema: new Schema( |
||
309 | type: 'integer', |
||
310 | default: null, |
||
311 | enum: [0, 1], |
||
312 | nullable: true |
||
313 | ) |
||
314 | ), |
||
315 | new Parameter( |
||
316 | name: 'search', |
||
317 | description: 'Search for posts where the given keyword appears in either the name or description fields.', |
||
318 | in: 'query', |
||
319 | required: false, |
||
320 | schema: new Schema(type: 'string', default: null) |
||
321 | ), |
||
322 | new Parameter( |
||
323 | name: 'per_page', |
||
324 | description: 'Number of items per page', |
||
325 | in: 'query', |
||
326 | required: false, |
||
327 | schema: new Schema(type: 'integer', default: 10) |
||
328 | ), |
||
329 | new Parameter( |
||
330 | name: 'page', |
||
331 | description: 'Page number', |
||
332 | in: 'query', |
||
333 | required: false, |
||
334 | schema: new Schema(type: 'integer', default: 1) |
||
335 | ), |
||
336 | ], |
||
337 | responses: [ |
||
338 | new Response( |
||
339 | response: 200, |
||
340 | description: "Get posts successfully", |
||
341 | content: new JsonContent( |
||
342 | properties: [ |
||
343 | new Property( |
||
344 | property: 'error', |
||
345 | description: 'Error status', |
||
346 | type: 'boolean', |
||
347 | default: false |
||
348 | ), |
||
349 | new Property( |
||
350 | property: "data", |
||
351 | description: "Data of model", |
||
352 | type: "array", |
||
353 | items: new Items(ref: PostListResourceSchema::class) |
||
354 | ), |
||
355 | ] |
||
356 | ) |
||
357 | ), |
||
358 | new Response( |
||
359 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\BadRequestResponseSchema::class, |
||
360 | response: 400, |
||
361 | ), |
||
362 | new Response( |
||
363 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\ErrorNotFoundResponseSchema::class, |
||
364 | response: 404, |
||
365 | ), |
||
366 | new Response( |
||
367 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\InternalServerResponseSchema::class, |
||
368 | response: 500, |
||
369 | ), |
||
370 | ] |
||
371 | ) |
||
372 | ] |
||
373 | public function getFilters(Request $request): BaseHttpResponse|JsonResponse|JsonResource|RedirectResponse |
||
374 | { |
||
375 | $filters = FilterPost::setFilters($request->input()); |
||
376 | |||
377 | $data = $this->postRepository->getFilters((array) $filters); |
||
378 | |||
379 | return $this |
||
380 | ->httpResponse() |
||
381 | ->setData(ListPostResource::collection($data)) |
||
382 | ->toApiResponse(); |
||
383 | } |
||
385 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths