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