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