Conditions | 3 |
Paths | 3 |
Total Lines | 86 |
Code Lines | 61 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
45 | #[ |
||
46 | Get( |
||
47 | path: "/posts/{slug}/view-count", |
||
48 | operationId: "viewCountPostBySlug", |
||
49 | description: "Get views count of the post by slug |
||
50 | |||
51 | This API will get record from the database and return views count of the post by slug. |
||
52 | ", |
||
53 | summary: "Get views count of the post by slug", |
||
54 | tags: ["Post"], |
||
55 | parameters: [ |
||
56 | new Parameter( |
||
57 | name: 'slug', |
||
58 | description: 'Post slug', |
||
59 | in: 'path', |
||
60 | required: true, |
||
61 | schema: new Schema(type: 'string', example: 'php') |
||
62 | ), |
||
63 | ], |
||
64 | responses: [ |
||
65 | new Response( |
||
66 | response: 200, |
||
67 | description: "Get views count successfully", |
||
68 | content: new JsonContent( |
||
69 | properties: [ |
||
70 | new Property( |
||
71 | property: 'error', |
||
72 | description: 'Error status', |
||
73 | type: 'boolean', |
||
74 | default: false |
||
75 | ), |
||
76 | new Property( |
||
77 | property: "data", |
||
78 | ref: ViewCountResourceSchema::class, |
||
79 | description: "Data of model", |
||
80 | type: "object", |
||
81 | ), |
||
82 | ] |
||
83 | ) |
||
84 | ), |
||
85 | new Response( |
||
86 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\BadRequestResponseSchema::class, |
||
87 | response: 400, |
||
88 | ), |
||
89 | new Response( |
||
90 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\ErrorNotFoundResponseSchema::class, |
||
91 | response: 404, |
||
92 | ), |
||
93 | new Response( |
||
94 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\InternalServerResponseSchema::class, |
||
95 | response: 500, |
||
96 | ), |
||
97 | ] |
||
98 | ) |
||
99 | ] |
||
100 | public function __invoke(string $slug): BaseHttpResponse|JsonResponse|JsonResource|RedirectResponse |
||
101 | { |
||
102 | /** @var Slug $slug */ |
||
103 | $slug = SlugHelper::getSlug($slug, SlugHelper::getPrefix(Post::getBaseModel())); |
||
104 | |||
105 | if (!$slug) { |
||
106 | return $this |
||
107 | ->httpResponse() |
||
108 | ->setError() |
||
109 | ->setCode(404) |
||
110 | ->setMessage('Not found'); |
||
111 | } |
||
112 | |||
113 | $post = Post::query() |
||
114 | ->select(['id', 'views']) |
||
115 | ->whereId($slug->reference_id) |
||
116 | ->where('status', StatusEnum::PUBLISHED) |
||
117 | ->first(); |
||
118 | |||
119 | if (!$post) { |
||
120 | return $this |
||
121 | ->httpResponse() |
||
122 | ->setError() |
||
123 | ->setCode(404) |
||
124 | ->setMessage('Not found'); |
||
125 | } |
||
126 | |||
127 | return $this |
||
128 | ->httpResponse() |
||
129 | ->setData(new ViewCountResource($post)) |
||
130 | ->toApiResponse(); |
||
131 | } |
||
133 |
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