Conditions | 3 |
Paths | 3 |
Total Lines | 64 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | 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 |
||
48 | #[ |
||
49 | Get( |
||
50 | path: "/posts/{slug}/navigate", |
||
51 | operationId: "postGetNavigate", |
||
52 | description: "Get the previous and next posts by slug |
||
53 | This API will return both previous and next posts for navigation purposes. |
||
54 | ", |
||
55 | summary: "Get previous and next posts for navigation", |
||
56 | tags: ["Post"], |
||
57 | parameters: [ |
||
58 | new Parameter( |
||
59 | name: 'slug', |
||
60 | description: 'Post slug', |
||
61 | in: 'path', |
||
62 | required: true, |
||
63 | schema: new Schema(type: 'string') |
||
64 | ), |
||
65 | ], |
||
66 | responses: [ |
||
67 | new Response( |
||
68 | response: 200, |
||
69 | description: 'Navigation posts retrieved successfully', |
||
70 | ), |
||
71 | new Response( |
||
72 | response: 404, |
||
73 | description: 'Post not found', |
||
74 | ), |
||
75 | ] |
||
76 | ) |
||
77 | ] |
||
78 | public function __invoke(string $slug): BaseHttpResponse|JsonResponse|JsonResource|RedirectResponse |
||
79 | { |
||
80 | /** @var Slug $slugModel */ |
||
81 | $slugModel = SlugHelper::getSlug($slug, SlugHelper::getPrefix(Post::getBaseModel())); |
||
82 | |||
83 | if (!$slugModel) { |
||
84 | return $this |
||
85 | ->httpResponse() |
||
86 | ->setError() |
||
87 | ->setCode(404) |
||
88 | ->setMessage('Not found'); |
||
89 | } |
||
90 | |||
91 | $currentPost = Post::query() |
||
92 | ->where('id', $slugModel->reference_id) |
||
93 | ->where('status', StatusEnum::PUBLISHED) |
||
94 | ->with(['categories', 'tags']) |
||
95 | ->first(); |
||
96 | |||
97 | if (!$currentPost) { |
||
98 | return $this |
||
99 | ->httpResponse() |
||
100 | ->setError() |
||
101 | ->setCode(404) |
||
102 | ->setMessage('Not found'); |
||
103 | } |
||
104 | |||
105 | // Using service method for complex business logic |
||
106 | $navigationPosts = $this->postService->getNavigationPosts($currentPost); |
||
107 | |||
108 | return $this |
||
109 | ->httpResponse() |
||
110 | ->setData(new PostNavigateResource($navigationPosts)) |
||
111 | ->toApiResponse(); |
||
112 | } |
||
114 |
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