| Conditions | 6 |
| Paths | 16 |
| Total Lines | 73 |
| Code Lines | 61 |
| 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 |
||
| 77 | private function getAdminIndex($module) |
||
| 78 | { |
||
| 79 | $pc = Tdmcreate\Files\CreatePhpCode::getInstance(); |
||
| 80 | $xc = Tdmcreate\Files\CreateXoopsCode::getInstance(); |
||
| 81 | $axc = Tdmcreate\Files\Admin\AdminXoopsCode::getInstance(); |
||
| 82 | $moduleDirname = $module->getVar('mod_dirname'); |
||
| 83 | $tables = $this->getTableTables($module->getVar('mod_id'), 'table_order'); |
||
| 84 | $language = $this->getLanguage($moduleDirname, 'AM'); |
||
| 85 | $languageThereAre = $this->getLanguage($moduleDirname, 'AM', 'THEREARE_'); |
||
| 86 | |||
| 87 | $ret = $this->getSimpleString(''); |
||
| 88 | $ret .= $pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname, 'Common']); |
||
| 89 | $ret .= $pc->getPhpCodeIncludeDir('dirname(__DIR__)', 'preloads/autoloader', true); |
||
| 90 | $ret .= $this->getInclude(); |
||
| 91 | $ret .= $pc->getPhpCodeBlankLine(); |
||
| 92 | $ret .= $pc->getPhpCodeCommentLine('Template Index'); |
||
| 93 | $ret .= $axc->getAdminTemplateMain((string)$moduleDirname, 'index'); |
||
| 94 | $ret .= $pc->getPhpCodeBlankLine(); |
||
| 95 | $ret .= $pc->getPhpCodeCommentLine('Count elements'); |
||
| 96 | $tableName = null; |
||
| 97 | foreach (array_keys($tables) as $i) { |
||
| 98 | $tableName = $tables[$i]->getVar('table_name'); |
||
| 99 | $ucfTableName = ucfirst($tableName); |
||
| 100 | $ret .= $xc->getXcEqualsOperator("\$count{$ucfTableName}", "\${$tableName}Handler->getCount()"); |
||
| 101 | } |
||
| 102 | $ret .= $pc->getPhpCodeBlankLine(); |
||
| 103 | $ret .= $pc->getPhpCodeCommentLine('InfoBox Statistics'); |
||
| 104 | $ret .= $axc->getAxcAddInfoBox($language . 'STATISTICS'); |
||
| 105 | $ret .= $pc->getPhpCodeCommentLine('Info elements'); |
||
| 106 | $tableInstall = []; |
||
| 107 | foreach (array_keys($tables) as $i) { |
||
| 108 | $tableName = $tables[$i]->getVar('table_name'); |
||
| 109 | $tableInstall[] = $tables[$i]->getVar('table_install'); |
||
| 110 | $stuTableName = $languageThereAre . mb_strtoupper($tableName); |
||
| 111 | $ucfTableName = ucfirst($tableName); |
||
| 112 | $ret .= $axc->getAxcAddInfoBoxLine($stuTableName, "\$count{$ucfTableName}"); |
||
| 113 | } |
||
| 114 | |||
| 115 | if (null === $tableName) { |
||
| 116 | $ret .= $axc->getAxcAddInfoBoxLine('No statistics', '0'); |
||
| 117 | } |
||
| 118 | |||
| 119 | if (is_array($tables) && in_array(1, $tableInstall)) { |
||
| 120 | $ret .= $pc->getPhpCodeBlankLine(); |
||
| 121 | $ret .= $pc->getPhpCodeCommentLine('Upload Folders'); |
||
| 122 | $ret .= $xc->getXcEqualsOperator('$configurator', 'new Common\Configurator()'); |
||
| 123 | $cond = '$configurator->uploadFolders && is_array($configurator->uploadFolders)'; |
||
| 124 | $fe_action = $xc->getXcEqualsOperator('$folder[]', '$configurator->uploadFolders[$i]', '',"\t\t"); |
||
| 125 | $condIf = $pc->getPhpCodeForeach('configurator->uploadFolders', true, false, 'i', $fe_action, "\t"); |
||
| 126 | $ret .= $pc->getPhpCodeConditions($cond, '', '', $condIf, false); |
||
| 127 | |||
| 128 | $ret .= $pc->getPhpCodeCommentLine('Uploads Folders Created'); |
||
| 129 | $boxLine = $axc->getAxcAddConfigBoxLine('$folder[$i]', 'folder', '', "\t"); |
||
| 130 | $boxLine .= $axc->getAxcAddConfigBoxLine("array(\$folder[\$i], '777')", 'chmod', '', "\t"); |
||
| 131 | $ret .= $pc->getPhpCodeForeach('folder', true, false, 'i', $boxLine, '') . PHP_EOL; |
||
| 132 | } |
||
| 133 | $ret .= $pc->getPhpCodeCommentLine('Render Index'); |
||
| 134 | $ret .= $xc->getXcXoopsTplAssign('navigation', "\$adminObject->displayNavigation('index.php')"); |
||
| 135 | $ret .= $pc->getPhpCodeCommentLine('Test Data'); |
||
| 136 | $condIf = $xc->getXcXoopsLoadLanguage('admin/modulesadmin',"\t", 'system'); |
||
| 137 | $condIf .= $pc->getPhpCodeIncludeDir('dirname(__DIR__)', 'testdata/index', true, '','',"\t"); |
||
|
|
|||
| 138 | $condIf .= $axc->getAdminItemButton("constant('CO_' . \$moduleDirNameUpper . '_ADD_SAMPLEDATA')", '', '', $op = '__DIR__ . /../../testdata/index.php?op=load', $type = 'samplebutton', $t = "\t"); |
||
| 139 | $condIf .= $axc->getAdminItemButton("constant('CO_' . \$moduleDirNameUpper . '_SAVE_SAMPLEDATA')", '', '', $op = '__DIR__ . /../../testdata/index.php?op=save', $type = 'samplebutton', $t = "\t"); |
||
| 140 | $condIf .= "//" . $axc->getAdminItemButton("constant('CO_' . \$moduleDirNameUpper . '_EXPORT_SCHEMA')", '', '', $op = '__DIR__ . /../../testdata/index.php?op=exportschema', $type = 'samplebutton', $t = "\t"); |
||
| 141 | $condIf .= $axc->getAdminDisplayButton('left', "\t"); |
||
| 142 | $cond = $xc->getXcGetConfig('displaySampleButton'); |
||
| 143 | $ret .= $pc->getPhpCodeConditions($cond, '', '', $condIf, false); |
||
| 144 | $ret .= $xc->getXcXoopsTplAssign('index', '$adminObject->displayIndex()'); |
||
| 145 | $ret .= $pc->getPhpCodeCommentLine('End Test Data'); |
||
| 146 | |||
| 147 | $ret .= $this->getInclude('footer'); |
||
| 148 | |||
| 149 | return $ret; |
||
| 150 | } |
||
| 170 |