Complex classes like UserXoopsVersion 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 UserXoopsVersion, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | class UserXoopsVersion extends TDMCreateFile |
||
|
|
|||
| 29 | { |
||
| 30 | /* |
||
| 31 | * @var mixed |
||
| 32 | */ |
||
| 33 | private $xc = null; |
||
| 34 | |||
| 35 | /* |
||
| 36 | * @var mixed |
||
| 37 | */ |
||
| 38 | private $uc = null; |
||
| 39 | |||
| 40 | /* |
||
| 41 | * @var array |
||
| 42 | */ |
||
| 43 | private $kw = array(); |
||
| 44 | |||
| 45 | /* |
||
| 46 | * @public function constructor |
||
| 47 | * @param null |
||
| 48 | */ |
||
| 49 | /** |
||
| 50 | * |
||
| 51 | */ |
||
| 52 | public function __construct() |
||
| 53 | { |
||
| 54 | parent::__construct(); |
||
| 55 | $this->phpcode = TDMCreatePhpCode::getInstance(); |
||
| 56 | $this->xc = TDMCreateXoopsCode::getInstance(); |
||
| 57 | $this->uc = UserXoopsCode::getInstance(); |
||
| 58 | } |
||
| 59 | |||
| 60 | /* |
||
| 61 | * @static function &getInstance |
||
| 62 | * @param null |
||
| 63 | */ |
||
| 64 | /** |
||
| 65 | * @return UserXoopsVersion |
||
| 66 | */ |
||
| 67 | public static function &getInstance() |
||
| 76 | |||
| 77 | /* |
||
| 78 | * @public function write |
||
| 79 | * @param $module |
||
| 80 | * @param mixed $table |
||
| 81 | * @param mixed $tables |
||
| 82 | * @param $filename |
||
| 83 | */ |
||
| 84 | /** |
||
| 85 | * @param $module |
||
| 86 | * @param $table |
||
| 87 | * @param $tables |
||
| 88 | * @param $filename |
||
| 89 | */ |
||
| 90 | public function write($module, $table, $tables, $filename) |
||
| 101 | |||
| 102 | /* |
||
| 103 | * @public function setKeywords |
||
| 104 | * @param mixed $keywords |
||
| 105 | */ |
||
| 106 | /** |
||
| 107 | * @param $keywords |
||
| 108 | */ |
||
| 109 | public function setKeywords($keywords) |
||
| 110 | { |
||
| 111 | if (is_array($keywords)) { |
||
| 112 | $this->kw = $keywords; |
||
| 113 | } else { |
||
| 114 | $this->kw[] = $keywords; |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | /* |
||
| 119 | * @public function getKeywords |
||
| 120 | * @param null |
||
| 121 | */ |
||
| 122 | /** |
||
| 123 | * @return array |
||
| 124 | */ |
||
| 125 | public function getKeywords() |
||
| 129 | |||
| 130 | /* |
||
| 131 | * @private function getXoopsVersionHeader |
||
| 132 | * @param $module |
||
| 133 | * @param $language |
||
| 134 | * |
||
| 135 | * @return string |
||
| 136 | */ |
||
| 137 | private function getXoopsVersionHeader($module, $language) |
||
| 138 | { |
||
| 139 | $date = date(_DBDATESTRING); |
||
| 140 | $ret = $this->getSimpleString(''); |
||
| 141 | $ret .= $this->phpcode->getPhpCodeCommentLine(); |
||
| 142 | $ret .= $this->xc->getXcEqualsOperator('$dirname ', 'basename(__DIR__)'); |
||
| 143 | $ret .= $this->getDashComment('Informations'); |
||
| 144 | $ha = (1 == $module->getVar('mod_admin')) ? 1 : 0; |
||
| 145 | $hm = (1 == $module->getVar('mod_user')) ? 1 : 0; |
||
| 146 | |||
| 147 | $descriptions = array('name' => "{$language}NAME", 'version' => "{$module->getVar('mod_version')}", 'description' => "{$language}DESC", |
||
| 148 | 'author' => "'{$module->getVar('mod_author')}'", 'author_mail' => "'{$module->getVar('mod_author_mail')}'", 'author_website_url' => "'{$module->getVar('mod_author_website_url')}'", |
||
| 149 | 'author_website_name' => "'{$module->getVar('mod_author_website_name')}'",'credits' => "'{$module->getVar('mod_credits')}'",'license' => "'{$module->getVar('mod_license')}'", |
||
| 150 | 'license_url' => "'www.gnu.org/licenses/gpl-2.0.html/'", 'help' => "'page=help'", 'release_info' => "'{$module->getVar('mod_release_info')}'", |
||
| 151 | 'release_file' => "XOOPS_URL . '/modules/{$module->getVar('mod_dirname')}/docs/{$module->getVar('mod_release_file')}'", 'release_date' => "'{$date}'", |
||
| 152 | 'manual' => "'{$module->getVar('mod_manual')}'", 'manual_file' => "XOOPS_URL . '/modules/{$module->getVar('mod_dirname')}/docs/{$module->getVar('mod_manual_file')}'", |
||
| 153 | 'min_php' => "'{$module->getVar('mod_min_php')}'", 'min_xoops' => "'{$module->getVar('mod_min_xoops')}'", 'min_admin' => "'{$module->getVar('mod_min_admin')}'", |
||
| 154 | 'min_db' => "array('mysql' => '{$module->getVar('mod_min_mysql')}', 'mysqli' => '{$module->getVar('mod_min_mysql')}')", 'image' => "'assets/images/{$module->getVar('mod_image')}'", |
||
| 155 | 'dirname' => 'basename(__DIR__)', 'dirmoduleadmin' => "'Frameworks/moduleclasses/moduleadmin'", 'sysicons16' => "'../../Frameworks/moduleclasses/icons/16'", |
||
| 156 | 'sysicons32' => "'../../Frameworks/moduleclasses/icons/32'", 'modicons16' => "'assets/icons/16'", 'modicons32' => "'assets/icons/32'", |
||
| 157 | 'demo_site_url' => "'{$module->getVar('mod_demo_site_url')}'", 'demo_site_name' => "'{$module->getVar('mod_demo_site_name')}'", 'support_url' => "'{$module->getVar('mod_support_url')}'", |
||
| 158 | 'support_name' => "'{$module->getVar('mod_support_name')}'", 'module_website_url' => "'{$module->getVar('mod_website_url')}'", 'module_website_name' => "'{$module->getVar('mod_website_name')}'", 'release' => "'{$module->getVar('mod_release')}'", 'module_status' => "'{$module->getVar('mod_status')}'", |
||
| 159 | 'system_menu' => '1', 'hasAdmin' => $ha, 'hasMain' => $hm, 'adminindex' => "'admin/index.php'", 'adminmenu' => "'admin/menu.php'", |
||
| 160 | 'onInstall' => "'include/install.php'", 'onUpdate' => "'include/update.php'", ); |
||
| 161 | |||
| 162 | $ret .= $this->uc->getUserModVersion(1, $descriptions); |
||
| 163 | |||
| 164 | return $ret; |
||
| 165 | } |
||
| 166 | |||
| 167 | /* |
||
| 168 | * @private function getXoopsVersionMySQL |
||
| 169 | * @param $moduleDirname |
||
| 170 | * @param $table |
||
| 171 | */ |
||
| 172 | /** |
||
| 173 | * @param $moduleDirname |
||
| 174 | * @param $table |
||
| 175 | * |
||
| 176 | * @return string |
||
| 177 | */ |
||
| 178 | private function getXoopsVersionMySQL($moduleDirname, $table, $tables) |
||
| 179 | { |
||
| 180 | $tableName = $table->getVar('table_name'); |
||
| 181 | $n = 1; |
||
| 182 | $ret = ''; |
||
| 183 | if (!empty($tableName)) { |
||
| 184 | $ret .= $this->getDashComment('Mysql'); |
||
| 185 | $ret .= $this->uc->getUserModVersion(2, "'sql/mysql.sql'", 'sqlfile', "'mysql'"); |
||
| 186 | $ret .= $this->phpcode->getPhpCodeCommentLine('Tables'); |
||
| 187 | |||
| 188 | foreach (array_keys($tables) as $t) { |
||
| 189 | $ret .= $this->uc->getUserModVersion(2, "'{$moduleDirname}_{$tables[$t]->getVar('table_name')}'", 'tables', $n); |
||
| 190 | ++$n; |
||
| 191 | } |
||
| 192 | unset($n); |
||
| 193 | } |
||
| 194 | |||
| 195 | return $ret; |
||
| 196 | } |
||
| 197 | |||
| 198 | /* |
||
| 199 | * @private function getXoopsVersionSearch |
||
| 200 | * @param $moduleDirname |
||
| 201 | */ |
||
| 202 | /** |
||
| 203 | * @param $moduleDirname |
||
| 204 | * |
||
| 205 | * @return string |
||
| 206 | */ |
||
| 207 | private function getXoopsVersionSearch($moduleDirname) |
||
| 208 | { |
||
| 209 | $ret = $this->getDashComment('Search'); |
||
| 210 | $ret .= $this->uc->getUserModVersion(1, 1, 'hasSearch'); |
||
| 211 | $ret .= $this->uc->getUserModVersion(2, "'include/search.inc.php'", 'search', "'file'"); |
||
| 212 | $ret .= $this->uc->getUserModVersion(2, "'{$moduleDirname}_search'", 'search', "'func'"); |
||
| 213 | |||
| 214 | return $ret; |
||
| 215 | } |
||
| 216 | |||
| 217 | /* |
||
| 218 | * @private function getXoopsVersionComments |
||
| 219 | * @param $moduleDirname |
||
| 220 | */ |
||
| 221 | /** |
||
| 222 | * @param $moduleDirname |
||
| 223 | * |
||
| 224 | * @return string |
||
| 225 | */ |
||
| 226 | private function getXoopsVersionComments($moduleDirname) |
||
| 227 | { |
||
| 228 | $ret = $this->getDashComment('Comments'); |
||
| 229 | $ret .= $this->uc->getUserModVersion(2, "'comments.php'", 'comments', "'pageName'"); |
||
| 230 | $ret .= $this->uc->getUserModVersion(2, "'com_id'", 'comments', "'itemName'"); |
||
| 231 | $ret .= $this->phpcode->getPhpCodeCommentLine('Comment callback functions'); |
||
| 232 | $ret .= $this->uc->getUserModVersion(2, "'include/comment_functions.php'", 'comments', "'callbackFile'"); |
||
| 233 | $descriptions = array('approve' => "'{$moduleDirname}CommentsApprove'", 'update' => "'{$moduleDirname}CommentsUpdate'"); |
||
| 234 | $ret .= $this->uc->getUserModVersion(3, $descriptions, 'comments', "'callback'"); |
||
| 235 | |||
| 236 | return $ret; |
||
| 237 | } |
||
| 238 | |||
| 239 | /* |
||
| 240 | * @private function getXoopsVersionTemplatesAdmin |
||
| 241 | * @param $moduleDirname |
||
| 242 | */ |
||
| 243 | /** |
||
| 244 | * @param $moduleDirname |
||
| 245 | * @param $tables |
||
| 246 | * |
||
| 247 | * @return string |
||
| 248 | */ |
||
| 249 | private function getXoopsVersionTemplatesAdmin($moduleDirname, $tables) |
||
| 270 | |||
| 271 | /* |
||
| 272 | * @private function getXoopsVersionTemplatesLine |
||
| 273 | * @param $moduleDirname |
||
| 274 | */ |
||
| 275 | /** |
||
| 276 | * @param $moduleDirname |
||
| 277 | * |
||
| 278 | * @return string |
||
| 279 | */ |
||
| 280 | private function getXoopsVersionTemplatesLine($moduleDirname, $type, $extra = '', $isAdmin = false) |
||
| 281 | { |
||
| 282 | $ret = ''; |
||
| 283 | $desc = "'description' => ''"; |
||
| 284 | $arrayFile = "array('file' =>"; |
||
| 285 | if ($isAdmin) { |
||
| 286 | $ret .= $this->uc->getUserModVersion(2, "{$arrayFile} '{$moduleDirname}_admin_{$type}.tpl', {$desc}, 'type' => 'admin')", 'templates', ''); |
||
| 287 | } else { |
||
| 288 | if ($extra !== '') { |
||
| 289 | $ret .= $this->uc->getUserModVersion(2, "{$arrayFile} '{$moduleDirname}_{$type}_{$extra}.tpl', {$desc})", 'templates', ''); |
||
| 290 | } else { |
||
| 291 | $ret .= $this->uc->getUserModVersion(2, "{$arrayFile} '{$moduleDirname}_{$type}.tpl', {$desc})", 'templates', ''); |
||
| 292 | } |
||
| 293 | } |
||
| 294 | |||
| 295 | return $ret; |
||
| 296 | } |
||
| 297 | |||
| 298 | /* |
||
| 299 | * @private function getXoopsVersionTemplatesUser |
||
| 300 | * @param $moduleDirname |
||
| 301 | */ |
||
| 302 | /** |
||
| 303 | * @param $moduleDirname |
||
| 304 | * |
||
| 305 | * @return string |
||
| 306 | */ |
||
| 307 | private function getXoopsVersionTemplatesUser($moduleDirname, $tables) |
||
| 363 | |||
| 364 | /* |
||
| 365 | * @private function getXoopsVersionSubmenu |
||
| 366 | * @param $language |
||
| 367 | */ |
||
| 368 | /** |
||
| 369 | * @param $language |
||
| 370 | * |
||
| 371 | * @return string |
||
| 372 | */ |
||
| 373 | private function getXoopsVersionSubmenu($language, $tables) |
||
| 374 | { |
||
| 375 | $ret = $this->getDashComment('Submenu'); |
||
| 376 | $i = 1; |
||
| 377 | $tableSubmit = array(); |
||
| 378 | foreach (array_keys($tables) as $t) { |
||
| 379 | $tableName = $tables[$t]->getVar('table_name'); |
||
| 380 | $tableSubmit[] = $tables[$t]->getVar('table_submit'); |
||
| 381 | if (1 == $tables[$t]->getVar('table_submenu')) { |
||
| 382 | $ret .= $this->phpcode->getPhpCodeCommentLine('Sub', $tableName); |
||
| 383 | $tname = array('name' => "{$language}SMNAME{$i}", 'url' => "'{$tableName}.php'"); |
||
| 384 | $ret .= $this->uc->getUserModVersion(3, $tname, 'sub', $i); |
||
| 385 | } |
||
| 386 | ++$i; |
||
| 387 | } |
||
| 388 | if (in_array(1, $tableSubmit)) { |
||
| 389 | $ret .= $this->phpcode->getPhpCodeCommentLine('Sub', 'Submit'); |
||
| 390 | $submit = array('name' => "{$language}SMNAME{$i}", 'url' => "'submit.php'"); |
||
| 391 | $ret .= $this->uc->getUserModVersion(3, $submit, 'sub', $i); |
||
| 392 | } |
||
| 393 | unset($i); |
||
| 394 | |||
| 395 | return $ret; |
||
| 396 | } |
||
| 397 | |||
| 398 | /* |
||
| 399 | * @private function getXoopsVersionBlocks |
||
| 400 | * @param $moduleDirname |
||
| 401 | * @param $language |
||
| 402 | */ |
||
| 403 | /** |
||
| 404 | * @param $moduleDirname |
||
| 405 | * @param $language |
||
| 406 | * |
||
| 407 | * @return string |
||
| 408 | */ |
||
| 409 | private function getXoopsVersionBlocks($moduleDirname, $tables, $language) |
||
| 434 | |||
| 435 | /* |
||
| 436 | * @private function getXoopsVersionTypeBlocks |
||
| 437 | * @param $moduleDirname |
||
| 438 | * @param $language |
||
| 439 | */ |
||
| 440 | /** |
||
| 441 | * @param $moduleDirname |
||
| 442 | * @param $language |
||
| 443 | * |
||
| 444 | * @return string |
||
| 445 | */ |
||
| 446 | private function getXoopsVersionTypeBlocks($moduleDirname, $tableName, $stuTableSoleName, $language, $type) |
||
| 459 | |||
| 460 | /* |
||
| 461 | * @private function getXoopsVersionConfig |
||
| 462 | * @param $moduleDirname |
||
| 463 | * @param $language |
||
| 464 | */ |
||
| 465 | /** |
||
| 466 | * @param $module |
||
| 467 | * @param $table |
||
| 468 | * @param $language |
||
| 469 | * |
||
| 470 | * @return string |
||
| 471 | */ |
||
| 472 | private function getXoopsVersionConfig($module, $table, $language) |
||
| 609 | |||
| 610 | /* |
||
| 611 | * @private function getNotificationsType |
||
| 612 | * @param $language |
||
| 613 | * @param $type |
||
| 614 | * @param $tableName |
||
| 615 | * @param $item |
||
| 616 | * @param $typeOfNotify |
||
| 617 | */ |
||
| 618 | /** |
||
| 619 | * @param $language |
||
| 620 | * @param $type |
||
| 621 | * @param $tableName |
||
| 622 | * @param $notifyFile |
||
| 623 | * @param $item |
||
| 624 | * @param $typeOfNotify |
||
| 625 | * |
||
| 626 | * @return string |
||
| 627 | */ |
||
| 628 | private function getNotificationsType($language, $type = 'category', $tableName, $notifyFile, $item, $typeOfNotify) |
||
| 653 | |||
| 654 | /* |
||
| 655 | * @private function getXoopsVersionNotifications |
||
| 656 | * @param $moduleDirname |
||
| 657 | * @param $language |
||
| 658 | */ |
||
| 659 | /** |
||
| 660 | * @param $moduleDirname |
||
| 661 | * @param $language |
||
| 662 | * |
||
| 663 | * @return string |
||
| 664 | */ |
||
| 665 | private function getXoopsVersionNotifications($module, $language) |
||
| 746 | |||
| 747 | /* |
||
| 748 | * @private function getXoopsVersionNotificationGlobal |
||
| 749 | */ |
||
| 750 | /** |
||
| 751 | * @param $language |
||
| 752 | * @param $type |
||
| 753 | * @param $name |
||
| 754 | * @param $title |
||
| 755 | * @param $from |
||
| 756 | * |
||
| 757 | * @return string |
||
| 758 | */ |
||
| 759 | private function getXoopsVersionNotificationGlobal($language, $type, $name, $title, $from, $num) |
||
| 770 | |||
| 771 | /* |
||
| 772 | * @private function getXoopsVersionNotificationCategory |
||
| 773 | */ |
||
| 774 | /** |
||
| 775 | * @param $language |
||
| 776 | * @param $type |
||
| 777 | * @param $name |
||
| 778 | * @param $title |
||
| 779 | * @param $from |
||
| 780 | * |
||
| 781 | * @return string |
||
| 782 | */ |
||
| 783 | private function getXoopsVersionNotificationCategory($language, $type, $name, $title, $file, $item, $allow, $num) |
||
| 794 | |||
| 795 | /* |
||
| 796 | * @private function getXoopsVersionNotificationTableName |
||
| 797 | */ |
||
| 798 | /** |
||
| 799 | * @param $language |
||
| 800 | * @param $type |
||
| 801 | * @param $name |
||
| 802 | * @param $title |
||
| 803 | * @param $file |
||
| 804 | * @param $item |
||
| 805 | * @param $allow |
||
| 806 | * |
||
| 807 | * @return string |
||
| 808 | */ |
||
| 809 | private function getXoopsVersionNotificationTableName($language, $type, $name, $title, $file, $item = 'cid', $allow = 1, $num) |
||
| 820 | |||
| 821 | /* |
||
| 822 | * @private function getXoopsVersionNotifications |
||
| 823 | */ |
||
| 824 | /** |
||
| 825 | * @param $language |
||
| 826 | * @param $type |
||
| 827 | * @param $name |
||
| 828 | * @param $title |
||
| 829 | * @param $from |
||
| 830 | * @param $item |
||
| 831 | * @param $mail |
||
| 832 | * |
||
| 833 | * @return string |
||
| 834 | */ |
||
| 835 | private function getXoopsVersionNotificationCodeComplete($language, $type, $name, $category, $admin = 1, $title, $table, $mail, $num) |
||
| 848 | |||
| 849 | /* |
||
| 850 | * @public function render |
||
| 851 | * @param null |
||
| 852 | */ |
||
| 853 | /** |
||
| 854 | * @return bool|string |
||
| 855 | */ |
||
| 856 | public function render() |
||
| 905 | } |
||
| 906 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.