Complex classes like GoodTillSystem 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 GoodTillSystem, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
25 | class GoodTillSystem extends Authorize { |
||
26 | |||
27 | /** |
||
28 | * Good Till: Connect |
||
29 | * |
||
30 | * @param string $subdomain |
||
31 | * @param string $username |
||
32 | * @param string $password |
||
33 | * @return void |
||
34 | */ |
||
35 | public static function connect( |
||
40 | |||
41 | /** |
||
42 | * Good Till: Prepare |
||
43 | * |
||
44 | * @param RESTInterface $model |
||
45 | * @return RESTInterface |
||
46 | */ |
||
47 | public static function prepare(RESTInterface $model, string $id = null): RESTInterface { |
||
53 | |||
54 | /** |
||
55 | * Good Till: API |
||
56 | * |
||
57 | * @param RESTInterface $model |
||
58 | * @return RESTInterface |
||
59 | */ |
||
60 | public static function api(RESTInterface $model): RESTInterface { |
||
63 | |||
64 | /** |
||
65 | * Good Till API: Customer |
||
66 | * |
||
67 | * @param string $id |
||
68 | * @return Customer |
||
69 | * |
||
70 | * @source https://apidoc.thegoodtill.com/#api-Customer |
||
71 | */ |
||
72 | public static function customer(string $id): Customer { |
||
75 | |||
76 | /** |
||
77 | * Good Till API: Customers |
||
78 | * |
||
79 | * @param null|string $id |
||
80 | * @return Customer |
||
81 | * |
||
82 | * @source https://apidoc.thegoodtill.com/#api-Customer |
||
83 | */ |
||
84 | public static function customers(string $id = null): Customer { |
||
87 | |||
88 | /** |
||
89 | * Good Till API: Customer Group |
||
90 | * |
||
91 | * @param null|string $id |
||
92 | * @return CustomerGroup |
||
93 | * |
||
94 | * @source https://apidoc.thegoodtill.com/#api-CustomerGroup |
||
95 | */ |
||
96 | public static function customerGroup(string $id): CustomerGroup { |
||
99 | |||
100 | /** |
||
101 | * Good Till API: Customer Group |
||
102 | * |
||
103 | * @param null|string $id |
||
104 | * @return CustomerGroup |
||
105 | * |
||
106 | * @source https://apidoc.thegoodtill.com/#api-CustomerGroup |
||
107 | */ |
||
108 | public static function customerGroups(string $id = null): CustomerGroup { |
||
111 | |||
112 | /** |
||
113 | * Good Till API: Product |
||
114 | * |
||
115 | * @param string $id |
||
116 | * @return Product |
||
117 | * |
||
118 | * @source https://apidoc.thegoodtill.com/#api-Product |
||
119 | */ |
||
120 | public static function product(string $id): Product { |
||
123 | |||
124 | /** |
||
125 | * Good Till API: Products |
||
126 | * |
||
127 | * @param null|string $id |
||
128 | * @return Product |
||
129 | * |
||
130 | * @source https://apidoc.thegoodtill.com/#api-Product |
||
131 | */ |
||
132 | public static function products(string $id = null): Product { |
||
135 | |||
136 | /** |
||
137 | * Good Till API: Brand |
||
138 | * |
||
139 | * @param string $id |
||
140 | * @return Brand |
||
141 | * |
||
142 | * @source https://apidoc.thegoodtill.com/#api-Brand |
||
143 | */ |
||
144 | public static function brand(string $id): Brand { |
||
147 | |||
148 | /** |
||
149 | * Create a new GoodTill instance. |
||
150 | * @param null|string $id |
||
151 | * @return Brand |
||
152 | * |
||
153 | * @source https://apidoc.thegoodtill.com/#api-Brand |
||
154 | */ |
||
155 | public static function brands(string $id = null): Brand { |
||
158 | |||
159 | /** |
||
160 | * Good Till API: Category |
||
161 | * |
||
162 | * @param string $id |
||
163 | * @return Category |
||
164 | * |
||
165 | * @source https://apidoc.thegoodtill.com/#api-Category |
||
166 | */ |
||
167 | public static function category(string $id): Category { |
||
170 | |||
171 | /** |
||
172 | * Good Till API: Categories |
||
173 | * |
||
174 | * @param null|string $id |
||
175 | * @return Category |
||
176 | * |
||
177 | * @source https://apidoc.thegoodtill.com/#api-Category |
||
178 | */ |
||
179 | public static function categories(string $id = null): Category { |
||
182 | |||
183 | /** |
||
184 | * Good Till API: Tag |
||
185 | * |
||
186 | * @param string $id |
||
187 | * @return Tag |
||
188 | * |
||
189 | * @source https://apidoc.thegoodtill.com/#api-Tag |
||
190 | */ |
||
191 | public static function tag(string $id): Tag { |
||
194 | |||
195 | /** |
||
196 | * Good Till API: Tags |
||
197 | * |
||
198 | * @param null|string $id |
||
199 | * @return Tag |
||
200 | * |
||
201 | * @source https://apidoc.thegoodtill.com/#api-Tag |
||
202 | */ |
||
203 | public static function tags(string $id = null): Tag { |
||
206 | |||
207 | /** |
||
208 | * Good Till API: Outlets |
||
209 | * |
||
210 | * @param string $id |
||
211 | * @return Supplier |
||
212 | * |
||
213 | * @source https://apidoc.thegoodtill.com/#api-Supplier |
||
214 | */ |
||
215 | public static function supplier(string $id): Supplier { |
||
218 | |||
219 | /** |
||
220 | * Good Till API: Suppliers |
||
221 | * |
||
222 | * @param null|string $id |
||
223 | * @return Supplier |
||
224 | * |
||
225 | * @source https://apidoc.thegoodtill.com/#api-Supplier |
||
226 | */ |
||
227 | public static function suppliers(string $id = null): Supplier { |
||
230 | |||
231 | /** |
||
232 | * Good Till API: Ingredient |
||
233 | * |
||
234 | * @param string $id |
||
235 | * @return Ingredient |
||
236 | * |
||
237 | * @source https://apidoc.thegoodtill.com/#api-Ingredient |
||
238 | */ |
||
239 | public static function ingredient(string $id): Ingredient { |
||
242 | |||
243 | /** |
||
244 | * Good Till API: Ingredients |
||
245 | * |
||
246 | * @param null|string $id |
||
247 | * @return Ingredient |
||
248 | * |
||
249 | * @source https://apidoc.thegoodtill.com/#api-Ingredient |
||
250 | */ |
||
251 | public static function ingredients(string $id = null): Ingredient { |
||
254 | |||
255 | /** |
||
256 | * Good Till API: Selling Layout |
||
257 | * |
||
258 | * @param string $id |
||
259 | * @return SellingLayout |
||
260 | * |
||
261 | * @source https://apidoc.thegoodtill.com/#api-SellingLayout |
||
262 | */ |
||
263 | public static function sellingLayout(string $id): SellingLayout { |
||
266 | |||
267 | /** |
||
268 | * Good Till API: Selling Layout |
||
269 | * |
||
270 | * @param null|string $id |
||
271 | * @return SellingLayout |
||
272 | * |
||
273 | * @source https://apidoc.thegoodtill.com/#api-SellingLayout |
||
274 | */ |
||
275 | public static function sellingLayouts(string $id = null): SellingLayout { |
||
278 | |||
279 | /** |
||
280 | * Good Till API: Ecommerce |
||
281 | * |
||
282 | * @param null|string $id |
||
283 | * @return Ecommerce |
||
284 | * |
||
285 | * @source https://apidoc.thegoodtill.com/#api-Ecommerce |
||
286 | */ |
||
287 | public static function ecommerce(string $id = null): Ecommerce { |
||
290 | |||
291 | /** |
||
292 | * Good Till API: Staff |
||
293 | * |
||
294 | * @param null|string $id |
||
295 | * @return Staff |
||
296 | * |
||
297 | * @source https://apidoc.thegoodtill.com/#api-Staff |
||
298 | */ |
||
299 | public static function staff(string $id = null): Staff { |
||
302 | |||
303 | /** |
||
304 | * Good Till API: Outlets |
||
305 | * |
||
306 | * @param null|string $id |
||
307 | * @return Outlet |
||
308 | * |
||
309 | * @source https://apidoc.thegoodtill.com/#api-Tag |
||
310 | */ |
||
311 | public static function staffClock(string $id = null) { |
||
314 | |||
315 | /** |
||
316 | * Good Till API: Sale |
||
317 | * |
||
318 | * @param string $id |
||
319 | * @return Sale |
||
320 | * |
||
321 | * @source https://apidoc.thegoodtill.com/#api-Tag |
||
322 | */ |
||
323 | public static function sale(string $id): Sales { |
||
326 | |||
327 | /** |
||
328 | * Good Till API: Sales |
||
329 | * |
||
330 | * @param null|string $id |
||
331 | * @return Sale |
||
332 | * |
||
333 | * @source https://apidoc.thegoodtill.com/#api-Tag |
||
334 | */ |
||
335 | public static function sales(string $id = null): Sale { |
||
338 | |||
339 | /** |
||
340 | * Good Till API: External Sale |
||
341 | * |
||
342 | * @param null|string $id |
||
343 | * @return ExternalSale |
||
344 | * |
||
345 | * @source https://apidoc.thegoodtill.com/#api-ExternalSale |
||
346 | */ |
||
347 | public static function externalSale(string $id = null): ExternalSale { |
||
350 | |||
351 | /** |
||
352 | * Good Till API: External Sale |
||
353 | * |
||
354 | * @param null|string $id |
||
355 | * @return ExternalSale |
||
356 | * |
||
357 | * @source https://apidoc.thegoodtill.com/#api-ExternalSale |
||
358 | */ |
||
359 | public static function external(): ExternalSale { |
||
362 | |||
363 | /** |
||
364 | * Good Till API: VAT Rate |
||
365 | * |
||
366 | * @param string $id |
||
367 | * @return VATRate |
||
368 | * |
||
369 | * @source https://apidoc.thegoodtill.com/#api-VatRate |
||
370 | */ |
||
371 | public static function vatRate(string $id): VATRate { |
||
374 | |||
375 | /** |
||
376 | * Good Till API: VAT Rates |
||
377 | * |
||
378 | * @param string|null $id |
||
379 | * @return VATRate |
||
380 | * |
||
381 | * @source https://apidoc.thegoodtill.com/#api-VatRate |
||
382 | */ |
||
383 | public static function vatRates(string $id = null): VATRate { |
||
386 | |||
387 | /** |
||
388 | * Good Till API: Payment Type |
||
389 | * |
||
390 | * @param string $id |
||
391 | * @return PaymentType |
||
392 | * |
||
393 | * @source https://apidoc.thegoodtill.com/#api-PaymentType |
||
394 | */ |
||
395 | public static function paymentType(string $id): PaymentType { |
||
398 | |||
399 | /** |
||
400 | * Good Till API: Payment Types |
||
401 | * |
||
402 | * @param null|string $id |
||
403 | * @return PaymentType |
||
404 | * |
||
405 | * @source https://apidoc.thegoodtill.com/#api-PaymentType |
||
406 | */ |
||
407 | public static function paymentTypes(string $id = null): PaymentType { |
||
410 | |||
411 | /** |
||
412 | * Good Till API: Register |
||
413 | * |
||
414 | * @return Register |
||
415 | * |
||
416 | * @source Undocument Feature |
||
417 | * @source https://apidoc.thegoodtill.com/#api-Register |
||
418 | */ |
||
419 | public static function register(string $id): Register { |
||
422 | |||
423 | /** |
||
424 | * Good Till API: Registers |
||
425 | * |
||
426 | * @param string|null $id |
||
427 | * @return Register |
||
428 | * |
||
429 | * @source https://apidoc.thegoodtill.com/#api-Register |
||
430 | */ |
||
431 | public static function registers(string $id = null): Register { |
||
434 | |||
435 | /** |
||
436 | * Good Till API: Vouchers |
||
437 | * |
||
438 | * @return Voucher |
||
439 | * |
||
440 | * @source Good Till Pro Feature |
||
441 | * @source https://apidoc.thegoodtill.com/#api-Voucher |
||
442 | */ |
||
443 | public static function vouchers(string $id = null): Voucher { |
||
446 | |||
447 | /** |
||
448 | * Good Till API: Loyalty |
||
449 | * |
||
450 | * @param string $id |
||
451 | * @return Loyalty |
||
452 | * |
||
453 | * @source https://apidoc.thegoodtill.com/#api-Loyalty |
||
454 | */ |
||
455 | public static function loyalty(string $id): Loyalty { |
||
458 | |||
459 | /** |
||
460 | * Good Till API: Loyalties |
||
461 | * |
||
462 | * @return Loyalty |
||
463 | * |
||
464 | * @source https://apidoc.thegoodtill.com/#api-Loyalty |
||
465 | */ |
||
466 | public static function loyalties(string $id = null): Loyalty { |
||
469 | |||
470 | /** |
||
471 | * Good Till API: Report |
||
472 | * |
||
473 | * @param string $id |
||
474 | * @return Report |
||
475 | * |
||
476 | * @source https://apidoc.thegoodtill.com/#api-Report |
||
477 | */ |
||
478 | public static function report(string $id): Report { |
||
481 | |||
482 | /** |
||
483 | * Good Till API: Reports |
||
484 | * |
||
485 | * @return Report |
||
486 | * |
||
487 | * @source https://apidoc.thegoodtill.com/#api-Report |
||
488 | */ |
||
489 | public static function reports(string $id = null): Report { |
||
492 | |||
493 | /** |
||
494 | * Good Till API: Outlet |
||
495 | * |
||
496 | * @param string $id |
||
497 | * @return Outlet |
||
498 | * |
||
499 | * @source https://apidoc.thegoodtill.com/#api-Outlet |
||
500 | */ |
||
501 | public static function outlet(string $id): Outlet { |
||
504 | |||
505 | /** |
||
506 | * Good Till API: Outlets |
||
507 | * |
||
508 | * @param null|string $id |
||
509 | * @return Outlet |
||
510 | * |
||
511 | * @source https://apidoc.thegoodtill.com/#api-Outlet |
||
512 | */ |
||
513 | public static function outlets(string $id = null): Outlet { |
||
516 | } |
||
517 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.