| Conditions | 1 |
| Paths | 1 |
| Total Lines | 63 |
| Code Lines | 46 |
| 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 |
||
| 30 | #[ |
||
| 31 | Get( |
||
| 32 | path: "/posts/{id}/increment-views", |
||
| 33 | operationId: "incrementViewCountPostById", |
||
| 34 | description: "Increment views count of the post by ID. Only adds 1 view per IP in 1 hour.", |
||
| 35 | summary: "Increment views count of the post by ID", |
||
| 36 | tags: ["Post"], |
||
| 37 | parameters: [ |
||
| 38 | new Parameter( |
||
| 39 | name: 'id', |
||
| 40 | description: 'Post Id', |
||
| 41 | in: 'path', |
||
| 42 | required: true, |
||
| 43 | schema: new Schema(type: 'integer', example: 1) |
||
| 44 | ), |
||
| 45 | ], |
||
| 46 | responses: [ |
||
| 47 | new Response( |
||
| 48 | response: 200, |
||
| 49 | description: "Success", |
||
| 50 | content: new JsonContent( |
||
| 51 | properties: [ |
||
| 52 | new Property( |
||
| 53 | property: 'error', |
||
| 54 | description: 'Error status', |
||
| 55 | type: 'boolean', |
||
| 56 | default: false |
||
| 57 | ), |
||
| 58 | new Property( |
||
| 59 | property: "data", |
||
| 60 | ref: ViewCountResourceSchema::class, |
||
| 61 | description: "Updated view count data", |
||
| 62 | type: "object", |
||
| 63 | ), |
||
| 64 | ] |
||
| 65 | ) |
||
| 66 | ), |
||
| 67 | new Response( |
||
| 68 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\BadRequestResponseSchema::class, |
||
| 69 | response: 400, |
||
| 70 | ), |
||
| 71 | new Response( |
||
| 72 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\ErrorNotFoundResponseSchema::class, |
||
| 73 | response: 404, |
||
| 74 | ), |
||
| 75 | new Response( |
||
| 76 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\InternalServerResponseSchema::class, |
||
| 77 | response: 500, |
||
| 78 | ), |
||
| 79 | ] |
||
| 80 | ) |
||
| 81 | ] |
||
| 82 | public function __invoke(Request $request, int $id): BaseHttpResponse|JsonResponse|JsonResource|RedirectResponse |
||
| 83 | { |
||
| 84 | $post = Post::findOrFail($id); |
||
| 85 | |||
| 86 | $ipAddress = $request->ip(); |
||
| 87 | $this->postService->trackView($post->id, $ipAddress); |
||
| 88 | |||
| 89 | return $this |
||
| 90 | ->httpResponse() |
||
| 91 | ->setData(new ViewCountResource($post)) |
||
| 92 | ->toApiResponse(); |
||
| 93 | } |
||
| 95 |
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