Passed
Pull Request — main (#69)
by
unknown
04:13 queued 44s
created

PostViewCountAction::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 60
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 44
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 60
rs 9.216

How to fix   Long Method   

Long Method

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:

1
<?php
2
3
namespace CSlant\Blog\Api\Http\Actions\Post;
4
5
use Botble\Base\Http\Responses\BaseHttpResponse;
0 ignored issues
show
Bug introduced by
The type Botble\Base\Http\Responses\BaseHttpResponse was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use CSlant\Blog\Api\Http\Resources\Post\ViewCountResource;
7
use CSlant\Blog\Api\OpenApi\Schemas\Resources\Post\ViewCountResourceSchema;
8
use CSlant\Blog\Core\Http\Actions\Action;
9
use CSlant\Blog\Core\Models\Post;
10
use Illuminate\Http\Request;
11
use OpenApi\Attributes\JsonContent;
12
use OpenApi\Attributes\Parameter;
13
use OpenApi\Attributes\Property;
14
use OpenApi\Attributes\Response;
15
use OpenApi\Attributes\Schema;
16
17
class PostViewCountAction extends Action
18
{
19
    #[
20
        PostAttribute(
21
            path: "/posts/{id}/increment-views",
22
            operationId: "incrementViewCountPostById",
23
            description: "Increment views count of the post by ID. Only adds 1 view per IP in 1 hour.",
24
            summary: "Increment views count of the post by ID",
25
            tags: ["Post"],
26
            parameters: [
27
                new Parameter(
28
                    name: 'id',
29
                    description: 'Post Id',
30
                    in: 'path',
31
                    required:  true,
32
                    schema: new Schema(type: 'integer', example: 1)
33
                ),
34
            ],
35
            responses: [
36
                new Response(
37
                    response: 200,
38
                    description: "Success",
39
                    content: new JsonContent(
40
                        properties: [
41
                            new Property(
42
                                property: 'error',
43
                                description: 'Error status',
44
                                type: 'boolean',
45
                                default: false
46
                            ),
47
                            new Property(
48
                                property: "data",
49
                                ref: ViewCountResourceSchema::class,
50
                                description: "Updated view count data",
51
                                type: "object",
52
                            ),
53
                        ]
54
                    )
55
                ),
56
                new Response(
57
                    ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\BadRequestResponseSchema::class,
58
                    response: 400,
59
                ),
60
                new Response(
61
                    ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\ErrorNotFoundResponseSchema::class,
62
                    response: 404,
63
                ),
64
                new Response(
65
                    ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\InternalServerResponseSchema::class,
66
                    response: 500,
67
                ),
68
            ]
69
        )
70
    ]
71
    public function __invoke(Request $request, int $id): BaseHttpResponse|JsonResponse|JsonResource|RedirectResponse
0 ignored issues
show
Bug introduced by
The type CSlant\Blog\Api\Http\Actions\Post\JsonResponse was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The type CSlant\Blog\Api\Http\Actions\Post\RedirectResponse was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The type CSlant\Blog\Api\Http\Actions\Post\JsonResource was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
72
    {
73
        $post = Post::findOrFail($id);
74
75
        return $this
76
            ->httpResponse()
77
            ->setData(new ViewCountResource($post))
78
            ->toApiResponse();
79
    }
80
}
81