Conditions | 3 |
Paths | 3 |
Total Lines | 96 |
Code Lines | 68 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
98 | #[ |
||
99 | Get( |
||
100 | path: "/categories/{slug}", |
||
101 | operationId: "categoryFilterBySlug", |
||
102 | description: "Get the category by slug |
||
103 | |||
104 | This API will get records from the database and return the category by slug. |
||
105 | ", |
||
106 | summary: "Get category by slug", |
||
107 | security: [['sanctum' => []]], |
||
108 | tags: ["Category"], |
||
109 | parameters: [ |
||
110 | new Parameter( |
||
111 | name: 'slug', |
||
112 | description: 'Category slug', |
||
113 | in: 'path', |
||
114 | required: true, |
||
115 | schema: new Schema(type: 'string', default: 'php') |
||
116 | ), |
||
117 | ], |
||
118 | responses: [ |
||
119 | new Response( |
||
120 | response: 200, |
||
121 | description: "Get category successfully", |
||
122 | content: new JsonContent( |
||
123 | properties: [ |
||
124 | new Property( |
||
125 | property: 'error', |
||
126 | description: 'Error status', |
||
127 | type: 'boolean', |
||
128 | default: false |
||
129 | ), |
||
130 | new Property( |
||
131 | property: 'data', |
||
132 | description: 'Data', |
||
133 | properties: [ |
||
134 | new Property( |
||
135 | property: 'category', |
||
136 | ref: CategoryModelResourceSchema::class, |
||
137 | description: 'Category', |
||
138 | type: 'object' |
||
139 | ), |
||
140 | ], |
||
141 | type: 'object' |
||
142 | ), |
||
143 | ] |
||
144 | ) |
||
145 | ), |
||
146 | new Response( |
||
147 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\BadRequestResponseSchema::class, |
||
148 | response: 400, |
||
149 | ), |
||
150 | new Response( |
||
151 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\ErrorNotFoundResponseSchema::class, |
||
152 | response: 404, |
||
153 | ), |
||
154 | new Response( |
||
155 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\InternalServerResponseSchema::class, |
||
156 | response: 500, |
||
157 | ), |
||
158 | ] |
||
159 | ) |
||
160 | ] |
||
161 | public function findBySlug(string $slug): JsonResponse|RedirectResponse|JsonResource|BaseHttpResponse |
||
162 | { |
||
163 | /** @var Slug $slug */ |
||
164 | $slug = SlugHelper::getSlug($slug, SlugHelper::getPrefix(Category::getBaseModel())); |
||
165 | |||
166 | if (!$slug) { |
||
167 | return $this |
||
168 | ->httpResponse() |
||
169 | ->setError() |
||
170 | ->setCode(404) |
||
171 | ->setMessage('Not found'); |
||
172 | } |
||
173 | |||
174 | $category = Category::query() |
||
175 | ->with(['slugable']) |
||
176 | ->where([ |
||
177 | 'id' => $slug->reference_id, |
||
178 | 'status' => StatusEnum::PUBLISHED, |
||
179 | ]) |
||
180 | ->first(); |
||
181 | |||
182 | if (!$category) { |
||
183 | return $this |
||
184 | ->httpResponse() |
||
185 | ->setError() |
||
186 | ->setCode(404) |
||
187 | ->setMessage('Not found'); |
||
188 | } |
||
189 | |||
190 | return $this |
||
191 | ->httpResponse() |
||
192 | ->setData(ListCategoryResource::make($category)) |
||
193 | ->toApiResponse(); |
||
194 | } |
||
196 |
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