| Conditions | 2 |
| Paths | 2 |
| Total Lines | 54 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 namespace XoopsModules\Tdmcreate\Files\Includes; |
||
| 88 | private function getCommonCode($module) |
||
| 89 | { |
||
| 90 | $pc = Tdmcreate\Files\CreatePhpCode::getInstance(); |
||
| 91 | $xc = Tdmcreate\Files\CreateXoopsCode::getInstance(); |
||
| 92 | $table = $this->getTable(); |
||
| 93 | $moduleDirname = $module->getVar('mod_dirname'); |
||
| 94 | $stuModuleDirname = mb_strtoupper($moduleDirname); |
||
|
|
|||
| 95 | $moduleAuthor = $module->getVar('mod_author'); |
||
| 96 | $moduleAuthorWebsiteName = $module->getVar('mod_author_website_name'); |
||
| 97 | $moduleAuthorWebsiteUrl = $module->getVar('mod_author_website_url'); |
||
| 98 | $moduleAuthorImage = str_replace(' ', '', mb_strtolower($moduleAuthor)); |
||
| 99 | $ret = <<<'EOT' |
||
| 100 | if (!defined('XOOPS_ICONS32_PATH')) { |
||
| 101 | define('XOOPS_ICONS32_PATH', XOOPS_ROOT_PATH . '/Frameworks/moduleclasses/icons/32'); |
||
| 102 | } |
||
| 103 | if (!defined('XOOPS_ICONS32_URL')) { |
||
| 104 | define('XOOPS_ICONS32_URL', XOOPS_URL . '/Frameworks/moduleclasses/icons/32'); |
||
| 105 | } |
||
| 106 | |||
| 107 | EOT; |
||
| 108 | $ret .= $this->getCommonDefines($moduleDirname, 'DIRNAME', "'{$moduleDirname}'"); |
||
| 109 | $ret .= $this->getCommonDefines($moduleDirname, 'PATH', "XOOPS_ROOT_PATH.'/modules/'.{$stuModuleDirname}_DIRNAME"); |
||
| 110 | $ret .= $this->getCommonDefines($moduleDirname, 'URL', "XOOPS_URL.'/modules/'.{$stuModuleDirname}_DIRNAME"); |
||
| 111 | $ret .= $this->getCommonDefines($moduleDirname, 'ICONS_PATH', "{$stuModuleDirname}_PATH.'/assets/icons'"); |
||
| 112 | $ret .= $this->getCommonDefines($moduleDirname, 'ICONS_URL', "{$stuModuleDirname}_URL.'/assets/icons'"); |
||
| 113 | $ret .= $this->getCommonDefines($moduleDirname, 'IMAGE_PATH', "{$stuModuleDirname}_PATH.'/assets/images'"); |
||
| 114 | $ret .= $this->getCommonDefines($moduleDirname, 'IMAGE_URL', "{$stuModuleDirname}_URL.'/assets/images'"); |
||
| 115 | $ret .= $this->getCommonDefines($moduleDirname, 'UPLOAD_PATH', "XOOPS_UPLOAD_PATH.'/'.{$stuModuleDirname}_DIRNAME"); |
||
| 116 | $ret .= $this->getCommonDefines($moduleDirname, 'UPLOAD_URL', "XOOPS_UPLOAD_URL.'/'.{$stuModuleDirname}_DIRNAME"); |
||
| 117 | |||
| 118 | $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id')); |
||
| 119 | $fieldElement = []; |
||
| 120 | foreach (array_keys($fields) as $f) { |
||
| 121 | $fieldElement[] = $fields[$f]->getVar('field_element'); |
||
| 122 | } |
||
| 123 | $ret .= $this->getCommonDefines($moduleDirname, 'UPLOAD_FILES_PATH', "{$stuModuleDirname}_UPLOAD_PATH.'/files'"); |
||
| 124 | $ret .= $this->getCommonDefines($moduleDirname, 'UPLOAD_FILES_URL', "{$stuModuleDirname}_UPLOAD_URL.'/files'"); |
||
| 125 | $ret .= $this->getCommonDefines($moduleDirname, 'UPLOAD_IMAGE_PATH', "{$stuModuleDirname}_UPLOAD_PATH.'/images'"); |
||
| 126 | $ret .= $this->getCommonDefines($moduleDirname, 'UPLOAD_IMAGE_URL', "{$stuModuleDirname}_UPLOAD_URL.'/images'"); |
||
| 127 | $ret .= $this->getCommonDefines($moduleDirname, 'UPLOAD_SHOTS_PATH', "{$stuModuleDirname}_UPLOAD_PATH.'/images/shots'"); |
||
| 128 | $ret .= $this->getCommonDefines($moduleDirname, 'UPLOAD_SHOTS_URL', "{$stuModuleDirname}_UPLOAD_URL.'/images/shots'"); |
||
| 129 | $ret .= $this->getCommonDefines($moduleDirname, 'ADMIN', "{$stuModuleDirname}_URL . '/admin/index.php'"); |
||
| 130 | $ret .= $xc->getXcEqualsOperator('$localLogo', "{$stuModuleDirname}_IMAGE_URL . '/{$moduleAuthorImage}_logo.png'"); |
||
| 131 | $ret .= $pc->getPhpCodeCommentLine('Module Information'); |
||
| 132 | $htmlCode = Tdmcreate\Files\CreateHtmlCode::getInstance(); |
||
| 133 | $img = $htmlCode->getHtmlImage('".$localLogo."', $moduleAuthorWebsiteName); |
||
| 134 | $anchor = $htmlCode->getHtmlAnchor($moduleAuthorWebsiteUrl, $img, $moduleAuthorWebsiteName, '_blank'); |
||
| 135 | $replace = $xc->getXcEqualsOperator('$copyright', '"' . $anchor . '"'); |
||
| 136 | $ret .= str_replace("\n", '', $replace) . PHP_EOL; |
||
| 137 | $ret .= $pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/xoopsrequest', true); |
||
| 138 | $ret .= $pc->getPhpCodeIncludeDir("{$stuModuleDirname}_PATH", 'class/helper', true); |
||
| 139 | $ret .= $pc->getPhpCodeIncludeDir("{$stuModuleDirname}_PATH", 'include/functions', true); |
||
| 140 | |||
| 141 | return $ret; |
||
| 142 | } |
||
| 161 |