Conditions | 1 |
Paths | 1 |
Total Lines | 88 |
Code Lines | 63 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
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 |
||
49 | #[ |
||
50 | Get( |
||
51 | path: "/posts", |
||
52 | operationId: "postGetAllWithFilter", |
||
53 | description: "Get all posts with pagination (10 items per page by default, page 1 by default) |
||
54 | |||
55 | This API will get records from the database and return them as a paginated list. |
||
56 | 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. |
||
57 | ", |
||
58 | summary: "Get all posts with pagination", |
||
59 | security: [['sanctum' => []]], |
||
60 | tags: ["Post"], |
||
61 | parameters: [ |
||
62 | new Parameter( |
||
63 | name: 'per_page', |
||
64 | description: 'Number of items per page', |
||
65 | in: 'query', |
||
66 | required: false, |
||
67 | schema: new Schema(type: 'integer', default: 10) |
||
68 | ), |
||
69 | new Parameter( |
||
70 | name: 'page', |
||
71 | description: 'Page number', |
||
72 | in: 'query', |
||
73 | required: false, |
||
74 | schema: new Schema(type: 'integer', default: 1) |
||
75 | ), |
||
76 | ], |
||
77 | responses: [ |
||
78 | new Response( |
||
79 | response: 200, |
||
80 | description: "Get posts successfully", |
||
81 | content: new JsonContent( |
||
82 | properties: [ |
||
83 | new Property( |
||
84 | property: 'error', |
||
85 | description: 'Error status', |
||
86 | type: 'boolean', |
||
87 | default: false |
||
88 | ), |
||
89 | new Property( |
||
90 | property: 'data', |
||
91 | description: 'Data', |
||
92 | properties: [ |
||
93 | new Property( |
||
94 | property: 'post', |
||
95 | ref: PostListResourceSchema::class, |
||
96 | description: 'Post', |
||
97 | type: 'object' |
||
98 | ), |
||
99 | ], |
||
100 | type: 'object' |
||
101 | ), |
||
102 | ] |
||
103 | ) |
||
104 | ), |
||
105 | new Response( |
||
106 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\BadRequestResponseSchema::class, |
||
107 | response: 400, |
||
108 | ), |
||
109 | new Response( |
||
110 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\ErrorNotFoundResponseSchema::class, |
||
111 | response: 404, |
||
112 | ), |
||
113 | new Response( |
||
114 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\InternalServerResponseSchema::class, |
||
115 | response: 500, |
||
116 | ), |
||
117 | ] |
||
118 | ) |
||
119 | ] |
||
120 | public function index(Request $request): BaseHttpResponse|JsonResponse|JsonResource|RedirectResponse |
||
121 | { |
||
122 | $data = $this |
||
123 | ->postRepository |
||
124 | ->advancedGet([ |
||
125 | 'with' => ['tags', 'categories', 'author', 'slugable'], |
||
126 | 'condition' => ['status' => StatusEnum::PUBLISHED->value], |
||
127 | 'paginate' => [ |
||
128 | 'per_page' => $request->integer('per_page', 10), |
||
129 | 'current_paged' => $request->integer('page', 1), |
||
130 | ], |
||
131 | ]); |
||
132 | |||
133 | return $this |
||
134 | ->httpResponse() |
||
135 | ->setData(ListPostResource::collection($data)) |
||
136 | ->toApiResponse(); |
||
137 | } |
||
325 |
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