Conditions | 2 |
Paths | 1 |
Total Lines | 73 |
Code Lines | 53 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
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 |
||
42 | #[ |
||
43 | Get( |
||
44 | path: "/tags", |
||
45 | operationId: "tagGetAllWithFilter", |
||
46 | description: "Get all tags with pagination (10 items per page by default, page 1 by default, page 1 by default) |
||
47 | |||
48 | This API will get records from the database and return them as a paginated list. |
||
49 | The default number of items per page is 10 and the default page number is 1. You can change these values by passing the `per_page` and `page` query parameters.", |
||
50 | summary: "Get all tags with pagination", |
||
51 | tags: ["Tag"], |
||
52 | parameters: [ |
||
53 | new Parameter( |
||
54 | name: 'per_page', |
||
55 | description: 'Number of items per page', |
||
56 | in: 'query', |
||
57 | required: false, |
||
58 | schema: new Schema(type: 'integer', default: 10) |
||
59 | ), |
||
60 | new Parameter( |
||
61 | name: 'page', |
||
62 | description: 'Page number', |
||
63 | in: 'query', |
||
64 | required: false, |
||
65 | schema: new Schema(type: 'integer', default: 1) |
||
66 | ), |
||
67 | ], |
||
68 | responses: [ |
||
69 | new Response( |
||
70 | response: 200, |
||
71 | description: "Get tags successfully", |
||
72 | content: new JsonContent( |
||
73 | properties: [ |
||
74 | new Property( |
||
75 | property: 'error', |
||
76 | description: 'Error status', |
||
77 | type: 'boolean', |
||
78 | default: false |
||
79 | ), |
||
80 | new Property( |
||
81 | property: "data", |
||
82 | description: "Data of model", |
||
83 | type: "array", |
||
84 | items: new Items(ref: TagModelResourceSchema::class) |
||
85 | ), |
||
86 | ] |
||
87 | ) |
||
88 | ), |
||
89 | new Response( |
||
90 | ref: BadRequestResponseSchema::class, |
||
91 | response: 400, |
||
92 | ), |
||
93 | new Response( |
||
94 | ref: ErrorNotFoundResponseSchema::class, |
||
95 | response: 404, |
||
96 | ), |
||
97 | new Response( |
||
98 | ref: InternalServerResponseSchema::class, |
||
99 | response: 500, |
||
100 | ), |
||
101 | ] |
||
102 | ) |
||
103 | ] |
||
104 | public function index(Request $request): BaseHttpResponse|JsonResponse|JsonResource|RedirectResponse |
||
105 | { |
||
106 | $data = Tag::query() |
||
107 | ->wherePublished() |
||
108 | ->with('slugable') |
||
109 | ->paginate($request->integer('per_page', 10) ?: 10); |
||
110 | |||
111 | return $this |
||
112 | ->httpResponse() |
||
113 | ->setData(TagResource::collection($data)) |
||
114 | ->toApiResponse(); |
||
115 | } |
||
217 |