| Conditions | 2 |
| Paths | 1 |
| Total Lines | 75 |
| Code Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
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 |
||
| 40 | #[ |
||
| 41 | Get( |
||
| 42 | path: "/categories", |
||
| 43 | operationId: "categoryGetAllWithFilter", |
||
| 44 | description: "Get all categories with pagination (10 items per page by default, page 1 by default) |
||
| 45 | |||
| 46 | This API will get records from the database and return them as a paginated list. |
||
| 47 | 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. |
||
| 48 | ", |
||
| 49 | summary: "Get all categories with pagination", |
||
| 50 | tags: ["Category"], |
||
| 51 | parameters: [ |
||
| 52 | new Parameter( |
||
| 53 | name: 'per_page', |
||
| 54 | description: 'Number of items per page', |
||
| 55 | in: 'query', |
||
| 56 | required: false, |
||
| 57 | schema: new Schema(type: 'integer', default: 10) |
||
| 58 | ), |
||
| 59 | new Parameter( |
||
| 60 | name: 'page', |
||
| 61 | description: 'Page number', |
||
| 62 | in: 'query', |
||
| 63 | required: false, |
||
| 64 | schema: new Schema(type: 'integer', default: 1) |
||
| 65 | ), |
||
| 66 | ], |
||
| 67 | responses: [ |
||
| 68 | new Response( |
||
| 69 | response: 200, |
||
| 70 | description: "Get categories successfully", |
||
| 71 | content: new JsonContent( |
||
| 72 | properties: [ |
||
| 73 | new Property( |
||
| 74 | property: 'error', |
||
| 75 | description: 'Error status', |
||
| 76 | type: 'boolean', |
||
| 77 | default: false |
||
| 78 | ), |
||
| 79 | new Property( |
||
| 80 | property: "data", |
||
| 81 | description: "Data of model", |
||
| 82 | type: "array", |
||
| 83 | items: new Items(ref: CategoryListResourceSchema::class) |
||
| 84 | ), |
||
| 85 | ] |
||
| 86 | ) |
||
| 87 | ), |
||
| 88 | new Response( |
||
| 89 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\BadRequestResponseSchema::class, |
||
| 90 | response: 400, |
||
| 91 | ), |
||
| 92 | new Response( |
||
| 93 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\ErrorNotFoundResponseSchema::class, |
||
| 94 | response: 404, |
||
| 95 | ), |
||
| 96 | new Response( |
||
| 97 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\InternalServerResponseSchema::class, |
||
| 98 | response: 500, |
||
| 99 | ), |
||
| 100 | ] |
||
| 101 | ) |
||
| 102 | ] |
||
| 103 | public function index(Request $request): BaseHttpResponse|JsonResponse|JsonResource|RedirectResponse |
||
| 104 | { |
||
| 105 | $data = Category::query() |
||
| 106 | ->wherePublished() |
||
| 107 | ->orderByDesc('created_at') |
||
| 108 | ->with(['slugable']) |
||
| 109 | ->paginate($request->integer('per_page', 10) ?: 10); |
||
| 110 | |||
| 111 | return $this |
||
| 112 | ->httpResponse() |
||
| 113 | ->setData(ListCategoryResource::collection($data)) |
||
| 114 | ->toApiResponse(); |
||
| 115 | } |
||
| 217 |
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