| Conditions | 2 |
| Paths | 2 |
| Total Lines | 104 |
| Code Lines | 77 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 44 | #[ |
||
| 45 | Get( |
||
| 46 | path: "/authors/{authorId}", |
||
| 47 | operationId: "profileAuthorByAuthorId", |
||
| 48 | description: "Get profile and list post of the author by author id |
||
| 49 | |||
| 50 | This API will get record from the database and return profile and list post of the author by author id. |
||
| 51 | ", |
||
| 52 | summary: "Get profile and list post of the author by author id", |
||
| 53 | tags: ["Author"], |
||
| 54 | parameters: [ |
||
| 55 | new Parameter( |
||
| 56 | name: 'authorId', |
||
| 57 | description: 'Author Id', |
||
| 58 | in: 'path', |
||
| 59 | required: true, |
||
| 60 | schema: new Schema(type: 'string', example: 'php') |
||
| 61 | ), |
||
| 62 | new Parameter( |
||
| 63 | name: 'order_by', |
||
| 64 | description: 'Can order by field: id, slug, created_at, ...', |
||
| 65 | in: 'query', |
||
| 66 | required: false, |
||
| 67 | schema: new Schema(type: 'string', default: 'created_at') |
||
| 68 | ), |
||
| 69 | new Parameter( |
||
| 70 | name: 'order', |
||
| 71 | description: 'Order direction: |
||
| 72 | ASC for ascending |
||
| 73 | DESC for descending', |
||
| 74 | in: 'query', |
||
| 75 | required: false, |
||
| 76 | schema: new Schema(type: 'string', default: 'ASC', enum: ['ASC', 'DESC']) |
||
| 77 | ), |
||
| 78 | new Parameter( |
||
| 79 | name: 'per_page', |
||
| 80 | description: 'Number of items per page', |
||
| 81 | in: 'query', |
||
| 82 | required: false, |
||
| 83 | schema: new Schema(type: 'integer', default: 10) |
||
| 84 | ), |
||
| 85 | new Parameter( |
||
| 86 | name: 'page', |
||
| 87 | description: 'Page number', |
||
| 88 | in: 'query', |
||
| 89 | required: false, |
||
| 90 | schema: new Schema(type: 'integer', default: 1) |
||
| 91 | ), |
||
| 92 | ], |
||
| 93 | responses: [ |
||
| 94 | new Response( |
||
| 95 | response: 200, |
||
| 96 | description: "Get author and list posts successfully", |
||
| 97 | content: new JsonContent( |
||
| 98 | properties: [ |
||
| 99 | new Property( |
||
| 100 | property: 'error', |
||
| 101 | description: 'Error status', |
||
| 102 | type: 'boolean', |
||
| 103 | default: false |
||
| 104 | ), |
||
| 105 | new Property( |
||
| 106 | property: "data", |
||
| 107 | ref: AuthorModelResourceSchema::class, |
||
| 108 | description: "Data of model", |
||
| 109 | type: "object", |
||
| 110 | ), |
||
| 111 | ] |
||
| 112 | ) |
||
| 113 | ), |
||
| 114 | new Response( |
||
| 115 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\BadRequestResponseSchema::class, |
||
| 116 | response: 400, |
||
| 117 | ), |
||
| 118 | new Response( |
||
| 119 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\ErrorNotFoundResponseSchema::class, |
||
| 120 | response: 404, |
||
| 121 | ), |
||
| 122 | new Response( |
||
| 123 | ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\InternalServerResponseSchema::class, |
||
| 124 | response: 500, |
||
| 125 | ), |
||
| 126 | ] |
||
| 127 | ) |
||
| 128 | ] |
||
| 129 | public function __invoke(int $authorId, Request $request): BaseHttpResponse|JsonResponse|JsonResource|RedirectResponse |
||
| 130 | { |
||
| 131 | $user = User::query() |
||
| 132 | ->with('posts') |
||
| 133 | ->whereId($authorId) |
||
| 134 | ->first(); |
||
| 135 | |||
| 136 | if (!$user) { |
||
| 137 | return $this |
||
| 138 | ->httpResponse() |
||
| 139 | ->setError() |
||
| 140 | ->setCode(404) |
||
| 141 | ->setMessage('Not found'); |
||
| 142 | } |
||
| 143 | |||
| 144 | return $this |
||
| 145 | ->httpResponse() |
||
| 146 | ->setData(new AuthorWithPostResource($user)) |
||
| 147 | ->toApiResponse(); |
||
| 148 | } |
||
| 150 |
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