Complex classes like XoopsGTicket 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 XoopsGTicket, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 9 | class XoopsGTicket |
||
| 10 | { |
||
| 11 | public $_errors = array(); |
||
| 12 | public $_latest_token = ''; |
||
| 13 | |||
| 14 | // render form as plain html |
||
| 15 | /** |
||
| 16 | * @param string $salt |
||
| 17 | * @param int $timeout |
||
| 18 | * @param string $area |
||
| 19 | * @return string |
||
| 20 | */ |
||
| 21 | public function getTicketHtml($salt = '', $timeout = 1800, $area = '') |
||
| 25 | |||
| 26 | // returns an object of XoopsFormHidden including theh ticket |
||
| 27 | /** |
||
| 28 | * @param string $salt |
||
| 29 | * @param int $timeout |
||
| 30 | * @param string $area |
||
| 31 | * @return XoopsFormHidden |
||
| 32 | */ |
||
| 33 | public function getTicketXoopsForm($salt = '', $timeout = 1800, $area = '') |
||
| 37 | |||
| 38 | // add a ticket as Hidden Element into XoopsForm |
||
| 39 | /** |
||
| 40 | * @param $form |
||
| 41 | * @param string $salt |
||
| 42 | * @param int $timeout |
||
| 43 | * @param string $area |
||
| 44 | */ |
||
| 45 | public function addTicketXoopsFormElement(&$form, $salt = '', $timeout = 1800, $area = '') |
||
| 49 | |||
| 50 | // returns an array for xoops_confirm() ; |
||
| 51 | /** |
||
| 52 | * @param string $salt |
||
| 53 | * @param int $timeout |
||
| 54 | * @param string $area |
||
| 55 | * @return array |
||
| 56 | */ |
||
| 57 | public function getTicketArray($salt = '', $timeout = 1800, $area = '') |
||
| 61 | |||
| 62 | // return GET parameter string. |
||
| 63 | /** |
||
| 64 | * @param string $salt |
||
| 65 | * @param bool $noamp |
||
| 66 | * @param int $timeout |
||
| 67 | * @param string $area |
||
| 68 | * @return string |
||
| 69 | */ |
||
| 70 | public function getTicketParamString($salt = '', $noamp = false, $timeout = 1800, $area = '') |
||
| 74 | |||
| 75 | // issue a ticket |
||
| 76 | /** |
||
| 77 | * @param string $salt |
||
| 78 | * @param int $timeout |
||
| 79 | * @param string $area |
||
| 80 | * @return string |
||
| 81 | */ |
||
| 82 | public function issue($salt = '', $timeout = 1800, $area = '') |
||
| 123 | |||
| 124 | // check a ticket |
||
| 125 | /** |
||
| 126 | * @param bool $post |
||
| 127 | * @param string $area |
||
| 128 | * @return bool |
||
| 129 | */ |
||
| 130 | public function check($post = true, $area = '') |
||
| 216 | |||
| 217 | // clear all stubs |
||
| 218 | public function clear() |
||
| 222 | |||
| 223 | // Ticket Using |
||
| 224 | /** |
||
| 225 | * @return bool |
||
| 226 | */ |
||
| 227 | public function using() |
||
| 235 | |||
| 236 | // return errors |
||
| 237 | /** |
||
| 238 | * @param bool $ashtml |
||
| 239 | * @return array|string |
||
| 240 | */ |
||
| 241 | public function getErrors($ashtml = true) |
||
| 254 | |||
| 255 | // end of class |
||
| 256 | } |
||
| 257 | |||
| 287 |