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