| Conditions | 3 |
| Paths | 3 |
| Total Lines | 89 |
| Code Lines | 63 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | 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 |
||
| 128 | #[ |
||
| 129 | Get( |
||
| 130 | path: "/categories/{slug}", |
||
| 131 | operationId: "categoryFilterBySlug", |
||
| 132 | description: "Get the category by slug |
||
| 133 | |||
| 134 | This API will get records from the database and return the category by slug. |
||
| 135 | ", |
||
| 136 | summary: "Get category by slug", |
||
| 137 | security: [['sanctum' => []]], |
||
| 138 | tags: ["Category"], |
||
| 139 | parameters: [ |
||
| 140 | new Parameter( |
||
| 141 | name: 'slug', |
||
| 142 | description: 'Category slug', |
||
| 143 | in: 'path', |
||
| 144 | required: true, |
||
| 145 | schema: new Schema(type: 'string', example: 'php') |
||
| 146 | ), |
||
| 147 | ], |
||
| 148 | responses: [ |
||
| 149 | new Response( |
||
| 150 | response: 200, |
||
| 151 | description: "Get category successfully", |
||
| 152 | content: new JsonContent( |
||
| 153 | properties: [ |
||
| 154 | new Property( |
||
| 155 | property: 'error', |
||
| 156 | description: 'Error status', |
||
| 157 | type: 'boolean', |
||
| 158 | default: false |
||
| 159 | ), |
||
| 160 | new Property( |
||
| 161 | property: "data", |
||
| 162 | ref: CategoryListResourceSchema::class, |
||
| 163 | description: "Data of model", |
||
| 164 | type: "object", |
||
| 165 | ), |
||
| 166 | ] |
||
| 167 | ) |
||
| 168 | ), |
||
| 169 | new Response( |
||
| 170 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\BadRequestResponseSchema::class, |
||
| 171 | response: 400, |
||
| 172 | ), |
||
| 173 | new Response( |
||
| 174 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\ErrorNotFoundResponseSchema::class, |
||
| 175 | response: 404, |
||
| 176 | ), |
||
| 177 | new Response( |
||
| 178 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\InternalServerResponseSchema::class, |
||
| 179 | response: 500, |
||
| 180 | ), |
||
| 181 | ] |
||
| 182 | ) |
||
| 183 | ] |
||
| 184 | public function findBySlug(string $slug): JsonResponse|RedirectResponse|JsonResource|BaseHttpResponse |
||
| 185 | { |
||
| 186 | /** @var Slug $slug */ |
||
| 187 | $slug = SlugHelper::getSlug($slug, SlugHelper::getPrefix(Category::getBaseModel())); |
||
| 188 | |||
| 189 | if (!$slug) { |
||
| 190 | return $this |
||
| 191 | ->httpResponse() |
||
| 192 | ->setError() |
||
| 193 | ->setCode(404) |
||
| 194 | ->setMessage('Not found'); |
||
| 195 | } |
||
| 196 | |||
| 197 | $category = Category::query() |
||
| 198 | ->with(['slugable']) |
||
| 199 | ->where([ |
||
| 200 | 'id' => $slug->reference_id, |
||
| 201 | 'status' => StatusEnum::PUBLISHED, |
||
| 202 | ]) |
||
| 203 | ->first(); |
||
| 204 | |||
| 205 | if (!$category) { |
||
| 206 | return $this |
||
| 207 | ->httpResponse() |
||
| 208 | ->setError() |
||
| 209 | ->setCode(404) |
||
| 210 | ->setMessage('Not found'); |
||
| 211 | } |
||
| 212 | |||
| 213 | return $this |
||
| 214 | ->httpResponse() |
||
| 215 | ->setData(ListCategoryResource::make($category)) |
||
| 216 | ->toApiResponse(); |
||
| 217 | } |
||
| 219 |
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