Conditions | 1 |
Paths | 1 |
Total Lines | 161 |
Code Lines | 123 |
Lines | 0 |
Ratio | 0 % |
Changes | 7 | ||
Bugs | 3 | Features | 3 |
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 of items categories', |
||
249 | in: 'query', |
||
250 | required: false, |
||
251 | schema: new Schema( |
||
252 | type: 'array', |
||
253 | default: null, |
||
254 | items: new Items(type: 'integer') |
||
255 | ) |
||
256 | ), |
||
257 | new Parameter( |
||
258 | name: 'categories_exclude', |
||
259 | description: 'Filter of items categories exclude', |
||
260 | in: 'query', |
||
261 | required: false, |
||
262 | schema: new Schema( |
||
263 | type: 'array', |
||
264 | default: null, |
||
265 | items: new Items(type: 'integer') |
||
266 | ) |
||
267 | ), |
||
268 | new Parameter( |
||
269 | name: 'exclude', |
||
270 | description: 'Filter of items exclude', |
||
271 | in: 'query', |
||
272 | required: false, |
||
273 | schema: new Schema( |
||
274 | type: 'array', |
||
275 | default: null, |
||
276 | items: new Items(type: 'integer') |
||
277 | ) |
||
278 | ), |
||
279 | new Parameter( |
||
280 | name: 'include', |
||
281 | description: 'Filter of items include', |
||
282 | in: 'query', |
||
283 | required: false, |
||
284 | schema: new Schema( |
||
285 | type: 'array', |
||
286 | default: null, |
||
287 | items: new Items(type: 'integer') |
||
288 | ) |
||
289 | ), |
||
290 | new Parameter( |
||
291 | name: 'author', |
||
292 | description: 'Filter of items author', |
||
293 | in: 'query', |
||
294 | required: false, |
||
295 | schema: new Schema( |
||
296 | type: 'array', |
||
297 | default: null, |
||
298 | items: new Items(type: 'integer') |
||
299 | ) |
||
300 | ), |
||
301 | new Parameter( |
||
302 | name: 'author_exclude', |
||
303 | description: 'Filter of items author exclude', |
||
304 | in: 'query', |
||
305 | required: false, |
||
306 | schema: new Schema( |
||
307 | type: 'array', |
||
308 | default: null, |
||
309 | items: new Items(type: 'integer') |
||
310 | ) |
||
311 | ), |
||
312 | new Parameter( |
||
313 | name: 'featured', |
||
314 | description: 'Filter of items featured', |
||
315 | in: 'query', |
||
316 | required: false, |
||
317 | schema: new Schema( |
||
318 | type: 'array', |
||
319 | default: null, |
||
320 | items: new Items(type: 'integer') |
||
321 | ) |
||
322 | ), |
||
323 | new Parameter( |
||
324 | name: 'search', |
||
325 | description: 'Filter of items search in name and description', |
||
326 | in: 'query', |
||
327 | required: false, |
||
328 | schema: new Schema( |
||
329 | type: 'array', |
||
330 | default: null, |
||
331 | items: new Items(type: 'integer') |
||
332 | ) |
||
333 | ), |
||
334 | new Parameter( |
||
335 | name: 'per_page', |
||
336 | description: 'Number of items per page', |
||
337 | in: 'query', |
||
338 | required: false, |
||
339 | schema: new Schema(type: 'integer', default: 10) |
||
340 | ), |
||
341 | new Parameter( |
||
342 | name: 'page', |
||
343 | description: 'Page number', |
||
344 | in: 'query', |
||
345 | required: false, |
||
346 | schema: new Schema(type: 'integer', default: 1) |
||
347 | ), |
||
348 | ], |
||
349 | responses: [ |
||
350 | new Response( |
||
351 | response: 200, |
||
352 | description: "Get posts successfully", |
||
353 | content: new JsonContent( |
||
354 | properties: [ |
||
355 | new Property( |
||
356 | property: 'error', |
||
357 | description: 'Error status', |
||
358 | type: 'boolean', |
||
359 | default: false |
||
360 | ), |
||
361 | new Property( |
||
362 | property: "data", |
||
363 | description: "Data of model", |
||
364 | type: "array", |
||
365 | items: new Items(ref: PostListResourceSchema::class) |
||
366 | ), |
||
367 | ] |
||
368 | ) |
||
369 | ), |
||
370 | new Response( |
||
371 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\BadRequestResponseSchema::class, |
||
372 | response: 400, |
||
373 | ), |
||
374 | new Response( |
||
375 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\ErrorNotFoundResponseSchema::class, |
||
376 | response: 404, |
||
377 | ), |
||
378 | new Response( |
||
379 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\InternalServerResponseSchema::class, |
||
380 | response: 500, |
||
381 | ), |
||
382 | ] |
||
383 | ) |
||
384 | ] |
||
385 | public function getFilters(Request $request): BaseHttpResponse|JsonResponse|JsonResource|RedirectResponse |
||
386 | { |
||
387 | $filters = FilterPost::setFilters($request->input()); |
||
388 | |||
389 | $data = $this->postRepository->getFilters((array) $filters); |
||
390 | |||
391 | return $this |
||
392 | ->httpResponse() |
||
393 | ->setData(ListPostResource::collection($data)) |
||
394 | ->toApiResponse(); |
||
395 | } |
||
397 |
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