Complex classes like Queries often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Queries, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
26 | class Queries extends Stats |
||
27 | { |
||
28 | |||
29 | public function orders() |
||
34 | |||
35 | |||
36 | public function orders_orderby($orderby) |
||
39 | |||
40 | |||
41 | |||
42 | public function orders_today() |
||
46 | |||
47 | |||
48 | |||
49 | public function orders_todayByStatus($status) |
||
53 | |||
54 | |||
55 | |||
56 | public function orders_thisMonth() |
||
60 | |||
61 | public function orders_thisMonthByStatus($status) |
||
65 | |||
66 | |||
67 | |||
68 | public function orders_thisYear() |
||
73 | |||
74 | |||
75 | public function orders_thisYearByStatus($status) |
||
80 | |||
81 | |||
82 | public function get_orders_with_status($status) |
||
86 | |||
87 | public function pending_orders() |
||
91 | |||
92 | public function cancelled_orders() |
||
96 | |||
97 | public function completed_orders() |
||
101 | |||
102 | public function getOrderById($orderid) |
||
106 | |||
107 | public function getOrdersOnDate($date) |
||
111 | |||
112 | |||
113 | public function getOrdersOnDateRange($startdate, $enddate) |
||
116 | |||
117 | |||
118 | /** Function to get an invoice */ |
||
119 | public function getInvoiceById($invoiceid) |
||
123 | |||
124 | |||
125 | /** Function to get an invoice */ |
||
126 | public function getInvoiceByOrderId($orderid) |
||
130 | |||
131 | |||
132 | |||
133 | /** |
||
134 | * |
||
135 | * User Queries |
||
136 | */ |
||
137 | |||
138 | |||
139 | /** Function to get given user orders */ |
||
140 | public function getUserOrders($userid) |
||
144 | |||
145 | |||
146 | /** Function to get given user orders by status */ |
||
147 | public function getUserOrdersByStatus($userid, $status) |
||
151 | |||
152 | |||
153 | |||
154 | |||
155 | /** Function to get orders by status */ |
||
156 | public function getOrdersByStatus( $status) |
||
160 | |||
161 | |||
162 | |||
163 | /** Function to get given user invoices */ |
||
164 | public function getUserInvoices($userid) |
||
168 | |||
169 | |||
170 | /** Function that returns total number of user invoices */ |
||
171 | public function totalUserInvoices($userid): int |
||
175 | |||
176 | |||
177 | |||
178 | |||
179 | /** Function to get given user invoices by status */ |
||
180 | public function getUserInvoiceByStatus($userid, $status) |
||
184 | |||
185 | |||
186 | |||
187 | |||
188 | /** Function to get given all invoices by status */ |
||
189 | public function getInvoiceByStatus( $status) |
||
193 | |||
194 | |||
195 | /** |
||
196 | * @param $userid |
||
197 | * @param $status |
||
198 | * @return mixed |
||
199 | * Function to get given user invoices by status |
||
200 | */ |
||
201 | public function sumUserInvoiceByStatus($userid, $status) : int |
||
205 | |||
206 | |||
207 | |||
208 | |||
209 | |||
210 | /** |
||
211 | * @param $status |
||
212 | * @return mixed |
||
213 | * Function to get given user invoices by status |
||
214 | */ |
||
215 | public function totalInvoiceByStatus($status) |
||
219 | |||
220 | |||
221 | |||
222 | |||
223 | /** |
||
224 | * @param $status |
||
225 | * @return mixed |
||
226 | * Function to get given user invoices by status |
||
227 | */ |
||
228 | public function sumInvoiceByStatus($status) |
||
232 | |||
233 | |||
234 | |||
235 | |||
236 | /** |
||
237 | * @param $userid |
||
238 | * @param $status |
||
239 | * @return mixed |
||
240 | * Function to get given user invoices by status |
||
241 | */ |
||
242 | public function totalUserInvoiceByStatus($userid, $status) |
||
246 | |||
247 | /** Function that gets full billing history */ |
||
248 | |||
249 | public function getAllBillingHistory() |
||
254 | |||
255 | |||
256 | /** Function that gets full user billing history*/ |
||
257 | |||
258 | public function getUserBillingHistory($userid) |
||
263 | |||
264 | |||
265 | |||
266 | |||
267 | public function getUserBillingHistoryByStartDate($userid, $start_date) |
||
272 | |||
273 | |||
274 | /** Function to get payment history of a given user for a given period */ |
||
275 | |||
276 | public function getUserBillingHistoryBetweenDates($userid, $start_date, $enddate) |
||
281 | |||
282 | |||
283 | /** |
||
284 | * Returns the model instance to be updated |
||
285 | */ |
||
286 | public function updateBillingHistory($invoiceid): BillingPayment |
||
290 | |||
291 | |||
292 | /** |
||
293 | * Returns the model instance to be updated |
||
294 | */ |
||
295 | public function updateInvoiceByInstance($invoiceid): Invoice |
||
299 | |||
300 | /** |
||
301 | * |
||
302 | * Returns updated invoice with new due_date |
||
303 | */ |
||
304 | public function updateDueDate($date, $invoiceid): Invoice |
||
311 | |||
312 | |||
313 | |||
314 | public function getBillingHistoryByStatus($status) |
||
319 | |||
320 | |||
321 | public function getUserBillingHistoryByStatus($userid, $status) |
||
326 | |||
327 | /** Return OrderItems for particular order |
||
328 | *@param $orderid |
||
329 | **/ |
||
330 | public function getOrderItems($orderid) |
||
335 | |||
336 | |||
337 | /** Return OrderItems for particular order gets invoiceid |
||
338 | *@param $invoiceid |
||
339 | **/ |
||
340 | public function getOrderItemsByInvoiceId($invoiceid) |
||
345 | |||
346 | public function getPaymentMethods(){ |
||
350 | |||
351 | public function getPaymentMethodById($pid){ |
||
355 | |||
356 | public function editPaymentMethod($pmethod_id, $pmethod) |
||
363 | |||
364 | |||
365 | public function addPaymentMethod(string $pmethod) |
||
376 | |||
377 | |||
378 | } |
||
379 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.