| Conditions | 17 |
| Paths | 3072 |
| Total Lines | 145 |
| Code Lines | 115 |
| 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 |
||
| 82 | private function getBlocksShow($moduleDirname, $tableName, $tableFieldname, $fields, $fieldId, $fieldParent = 0) |
||
| 83 | { |
||
| 84 | $pc = Tdmcreate\Files\CreatePhpCode::getInstance(); |
||
| 85 | $xc = Tdmcreate\Files\CreateXoopsCode::getInstance(); |
||
| 86 | $stuModuleDirname = mb_strtoupper($moduleDirname); |
||
| 87 | $ucfTableName = ucfirst($tableName); |
||
| 88 | $critName = 'cr' . $ucfTableName; |
||
| 89 | |||
| 90 | $ret = $pc->getPhpCodeCommentMultiLine(['Function' => 'show block', '@param $options' => '', '@return' => 'array']); |
||
| 91 | |||
| 92 | $func = $pc->getPhpCodeIncludeDir("XOOPS_ROOT_PATH . '/modules/{$moduleDirname}/class/{$tableName}.php'",'',true, true, '', "\t"); |
||
| 93 | $func .= $xc->getXcEqualsOperator('$myts', 'MyTextSanitizer::getInstance()', '',"\t"); |
||
| 94 | $func .= $xc->getXcXoopsTplAssign("{$moduleDirname}_upload_url","{$stuModuleDirname}_UPLOAD_URL",'',"\t"); |
||
|
|
|||
| 95 | $func .= $xc->getXcEqualsOperator('$block ', '[]', '',"\t"); |
||
| 96 | $func .= $xc->getXcEqualsOperator('$typeBlock ', '$options[0]','',"\t"); |
||
| 97 | $func .= $xc->getXcEqualsOperator('$limit ', '$options[1]','',"\t"); |
||
| 98 | $func .= $xc->getXcEqualsOperator('$lenghtTitle', '$options[2]','',"\t"); |
||
| 99 | $func .= $xc->getXcEqualsOperator('$helper ', 'Helper::getInstance()','',"\t"); |
||
| 100 | $func .= $xc->getXcHandlerLine($tableName, "\t"); |
||
| 101 | $func .= $xc->getXcCriteriaCompo($critName, "\t"); |
||
| 102 | $func .= $pc->getPhpCodeArrayShift('$options', "\t"); |
||
| 103 | $func .= $pc->getPhpCodeArrayShift('$options', "\t"); |
||
| 104 | $func .= $pc->getPhpCodeArrayShift('$options', "\t"); |
||
| 105 | $func .= $pc->getPhpCodeBlankLine(); |
||
| 106 | |||
| 107 | //content if: parent |
||
| 108 | $contIf = $xc->getXcEqualsOperator("\${$tableName}", "{$moduleDirname}_getMyItemIds('{$moduleDirname}_view', '{$moduleDirname}')", null, "\t"); |
||
| 109 | $crit = $xc->getXcCriteria('', "'cid'", "'(' . implode(',', \${$tableName}) . ')'", "'IN'", true); |
||
| 110 | $contIf .= $xc->getXcCriteriaAdd($critName, $crit, "\t"); |
||
| 111 | $crit = $xc->getXcCriteria('', "'{$fieldId}'", "{$moduleDirname}_block_addCatSelect(\$options)", "'IN'", true); |
||
| 112 | $contIf2 = $xc->getXcCriteriaAdd($critName, $crit, "\t\t"); |
||
| 113 | $contIf .= $pc->getPhpCodeConditions('1 != (count(\$options) && 0 == \$options[0])', null, null, $contIf2, false, "\t"); |
||
| 114 | $crit = $xc->getXcCriteria('', "'{$fieldId}'", '0', "'!='", true); |
||
| 115 | $contIf2 = $xc->getXcCriteriaAdd($critName, $crit, "\t\t"); |
||
| 116 | $contIf2 .= $xc->getXcCriteriaSetSort($critName, "'{$fieldId}'", "\t\t"); |
||
| 117 | $contIf2 .= $xc->getXcCriteriaSetOrder($critName, "'ASC'", "\t\t"); |
||
| 118 | $contIf .= $pc->getPhpCodeConditions('$typeBlock', null, null, $contIf2, false, "\t"); |
||
| 119 | |||
| 120 | //content else: parent |
||
| 121 | //search for SelectStatus field |
||
| 122 | $fieldStatus = ''; |
||
| 123 | $critStatus = ''; |
||
| 124 | foreach ($fields as $field) { |
||
| 125 | if ($field->getVar('field_element') == 16) { |
||
| 126 | $fieldStatus = $field->getVar('field_name'); |
||
| 127 | } |
||
| 128 | } |
||
| 129 | if ('' !== $fieldStatus) { |
||
| 130 | $crit = $xc->getXcCriteria('', "'{$fieldStatus}'", 'Constants::PERM_GLOBAL_VIEW', '', true); |
||
| 131 | $critStatus .= $xc->getXcCriteriaAdd($critName, $crit, "\t\t\t"); |
||
| 132 | } |
||
| 133 | |||
| 134 | $case1[] = $pc->getPhpCodeCommentLine("For the block: {$tableName} last",'',"\t\t\t"); |
||
| 135 | if ('' !== $fieldStatus) { |
||
| 136 | $case1[] = $critStatus; |
||
| 137 | } |
||
| 138 | $case1[] = $xc->getXcCriteriaSetSort($critName, "'{$tableFieldname}_date'","\t\t\t"); |
||
| 139 | $case1[] = $xc->getXcCriteriaSetOrder($critName, "'DESC'","\t\t\t"); |
||
| 140 | $case2[] = $pc->getPhpCodeCommentLine("For the block: {$tableName} new",'',"\t\t\t"); |
||
| 141 | if ('' !== $fieldStatus) { |
||
| 142 | $case2[] = $critStatus; |
||
| 143 | } |
||
| 144 | $crit = $xc->getXcCriteria('', "'{$tableFieldname}_date'", 'strtotime(date(_SHORTDATESTRING))', "'>='", true); |
||
| 145 | $case2[] = $xc->getXcCriteriaAdd($critName, $crit,"\t\t\t"); |
||
| 146 | $crit = $xc->getXcCriteria('', "'{$tableFieldname}_date'", 'strtotime(date(_SHORTDATESTRING))+86400', "'<='", true); |
||
| 147 | $case2[] = $xc->getXcCriteriaAdd($critName, $crit,"\t\t\t"); |
||
| 148 | $case2[] = $xc->getXcCriteriaSetSort($critName, "'{$tableFieldname}_date'","\t\t\t"); |
||
| 149 | $case2[] = $xc->getXcCriteriaSetOrder($critName, "'ASC'","\t\t\t"); |
||
| 150 | $case3[] = $pc->getPhpCodeCommentLine("For the block: {$tableName} hits",'',"\t\t\t"); |
||
| 151 | if ('' !== $fieldStatus) { |
||
| 152 | $case3[] = $critStatus; |
||
| 153 | } |
||
| 154 | $case3[] = $xc->getXcCriteriaSetSort($critName, "'{$tableFieldname}_hits'","\t\t\t"); |
||
| 155 | $case3[] = $xc->getXcCriteriaSetOrder($critName, "'DESC'","\t\t\t"); |
||
| 156 | $case4[] = $pc->getPhpCodeCommentLine("For the block: {$tableName} top",'',"\t\t\t"); |
||
| 157 | if ('' !== $fieldStatus) { |
||
| 158 | $case4[] = $critStatus; |
||
| 159 | } |
||
| 160 | $case4[] = $xc->getXcCriteriaAdd($critName, $crit,"\t\t\t"); |
||
| 161 | $case4[] = $xc->getXcCriteriaSetSort($critName, "'{$tableFieldname}_top'","\t\t\t"); |
||
| 162 | $case4[] = $xc->getXcCriteriaSetOrder($critName, "'ASC'","\t\t\t"); |
||
| 163 | $case5[] = $pc->getPhpCodeCommentLine("For the block: {$tableName} random",'',"\t\t\t"); |
||
| 164 | if ('' !== $fieldStatus) { |
||
| 165 | $case5[] = $critStatus; |
||
| 166 | } |
||
| 167 | $case5[] = $xc->getXcCriteriaAdd($critName, $crit,"\t\t\t"); |
||
| 168 | $case5[] = $xc->getXcCriteriaSetSort($critName, "'RAND()'","\t\t\t"); |
||
| 169 | $cases = [ |
||
| 170 | 'last' => $case1, |
||
| 171 | 'new' => $case2, |
||
| 172 | 'hits' => $case3, |
||
| 173 | 'top' => $case4, |
||
| 174 | 'random' => $case5, |
||
| 175 | ]; |
||
| 176 | $contSwitch = $pc->getPhpCodeCaseSwitch($cases, true, false, "\t\t"); |
||
| 177 | $contElse = $pc->getPhpCodeSwitch('typeBlock', $contSwitch, "\t"); |
||
| 178 | //end: content else: parent |
||
| 179 | if (1 == $fieldParent) { |
||
| 180 | $func .= $contIf; |
||
| 181 | } else { |
||
| 182 | $func .= $contElse; |
||
| 183 | } |
||
| 184 | $func .= $pc->getPhpCodeBlankLine(); |
||
| 185 | |||
| 186 | $func .= $xc->getXcCriteriaSetLimit($critName, '$limit', "\t"); |
||
| 187 | $func .= $xc->getXcHandlerAllClear("{$tableName}All", $tableName, "\${$critName}", "\t"); |
||
| 188 | $func .= $pc->getPhpCodeUnset($critName, "\t"); |
||
| 189 | $contentForeach = ''; |
||
| 190 | foreach (array_keys($fields) as $f) { |
||
| 191 | $fieldName = $fields[$f]->getVar('field_name'); |
||
| 192 | // Verify if table_fieldname is not empty |
||
| 193 | //$lpFieldName = !empty($tableFieldname) ? substr($fieldName, 0, strpos($fieldName, '_')) : $tableName; |
||
| 194 | $rpFieldName = $this->getRightString($fieldName); |
||
| 195 | $fieldElement = $fields[$f]->getVar('field_element'); |
||
| 196 | if (1 == $fields[$f]->getVar('field_block')) { |
||
| 197 | switch ($fieldElement) { |
||
| 198 | case 2: |
||
| 199 | $contentForeach .= $xc->getXcEqualsOperator("\$block[\$i]['{$rpFieldName}']", "\$myts->htmlSpecialChars(\${$tableName}All[\$i]->getVar('{$fieldName}'))", null, "\t\t\t"); |
||
| 200 | break; |
||
| 201 | case 3: |
||
| 202 | case 4: |
||
| 203 | $contentForeach .= $xc->getXcEqualsOperator("\$block[\$i]['{$rpFieldName}']", "strip_tags(\${$tableName}All[\$i]->getVar('{$fieldName}'))", null, "\t\t\t"); |
||
| 204 | break; |
||
| 205 | case 8: |
||
| 206 | $contentForeach .= $xc->getXcEqualsOperator("\$block[\$i]['{$rpFieldName}']", "\XoopsUser::getUnameFromId(\${$tableName}All[\$i]->getVar('{$fieldName}'))", null, "\t\t\t"); |
||
| 207 | break; |
||
| 208 | case 15: |
||
| 209 | $contentForeach .= $xc->getXcEqualsOperator("\$block[\$i]['{$rpFieldName}']","formatTimeStamp(\${$tableName}All[\$i]->getVar('{$fieldName}'))", null, "\t\t\t"); |
||
| 210 | break; |
||
| 211 | default: |
||
| 212 | $contentForeach .= $xc->getXcEqualsOperator("\$block[\$i]['{$rpFieldName}']","\${$tableName}All[\$i]->getVar('{$fieldName}')", null, "\t\t\t"); |
||
| 213 | break; |
||
| 214 | } |
||
| 215 | } |
||
| 216 | } |
||
| 217 | $foreach = $pc->getPhpCodeForeach("{$tableName}All", true, false, 'i', $contentForeach, "\t\t"); |
||
| 218 | |||
| 219 | $func .= $pc->getPhpCodeConditions("count(\${$tableName}All)", ' > ', '0', $foreach, false, "\t"); |
||
| 220 | $func .= $pc->getPhpCodeBlankLine(); |
||
| 221 | $func .= $this->getSimpleString('return $block;',"\t"); |
||
| 222 | $func .= $pc->getPhpCodeBlankLine(); |
||
| 223 | |||
| 224 | $ret .= $pc->getPhpCodeFunction("b_{$moduleDirname}_{$tableName}_show", '$options', $func, '', false, ""); |
||
| 225 | |||
| 226 | return $ret; |
||
| 227 | } |
||
| 327 |