| Conditions | 10 |
| Paths | 38 |
| Total Lines | 71 |
| Code Lines | 54 |
| 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 | public function getNotificationsFunction($moduleDirname) |
||
| 78 | { |
||
| 79 | $pc = Tdmcreate\Files\CreatePhpCode::getInstance(); |
||
| 80 | $xc = Tdmcreate\Files\CreateXoopsCode::getInstance(); |
||
| 81 | $stuModuleDirname = mb_strtoupper($moduleDirname); |
||
| 82 | $tables = $this->getTables(); |
||
| 83 | $t = "\t"; |
||
| 84 | $ret = $pc->getPhpCodeCommentMultiLine(['comment' => 'callback functions','' => '', '@param $category' => '', '@param $item_id' => '', '@return' => 'array item|null']); |
||
| 85 | $func = $xc->getXcGetGlobal(['xoopsDB'], $t); |
||
| 86 | $func .= $pc->getPhpCodeBlankLine(); |
||
| 87 | $contIf = $pc->getPhpCodeDefine($stuModuleDirname . '_URL',"XOOPS_URL . '/modules/{$moduleDirname}'", $t . "\t"); |
||
| 88 | $func .= $pc->getPhpCodeConditions("!defined('{$stuModuleDirname}_URL')", '','',$contIf, false, $t); |
||
| 89 | $func .= $pc->getPhpCodeBlankLine(); |
||
| 90 | |||
| 91 | $case[] = $xc->getXcEqualsOperator("\$item['name']", "''",'',$t . "\t\t"); |
||
|
|
|||
| 92 | $case[] = $xc->getXcEqualsOperator("\$item['url'] ", "''",'',$t . "\t\t"); |
||
| 93 | $case[] = $this->getSimpleString('return $item;', $t . "\t\t"); |
||
| 94 | $cases = [ |
||
| 95 | 'global' => $case, |
||
| 96 | ]; |
||
| 97 | $contentSwitch = $pc->getPhpCodeCaseSwitch($cases, false, false, $t . "\t"); |
||
| 98 | unset($case); |
||
| 99 | |||
| 100 | foreach (array_keys($tables) as $i) { |
||
| 101 | if (1 === (int)$tables[$i]->getVar('table_notifications')) { |
||
| 102 | $tableName = $tables[$i]->getVar('table_name'); |
||
| 103 | $fieldParent = false; |
||
| 104 | $fields = $this->getTableFields($tables[$i]->getVar('table_mid'), $tables[$i]->getVar('table_id')); |
||
| 105 | $fieldId = ''; |
||
| 106 | $fieldMain = ''; |
||
| 107 | foreach (array_keys($fields) as $f) { |
||
| 108 | $fieldName = $fields[$f]->getVar('field_name'); |
||
| 109 | if ((0 == $f) && (1 == $tables[$i]->getVar('table_autoincrement'))) { |
||
| 110 | $fieldId = $fieldName; |
||
| 111 | } |
||
| 112 | if (1 == $fields[$f]->getVar('field_parent')) { |
||
| 113 | $fieldParent = $fieldName; |
||
| 114 | } |
||
| 115 | if (1 == $fields[$f]->getVar('field_main')) { |
||
| 116 | $fieldMain = $fieldName; |
||
| 117 | } |
||
| 118 | } |
||
| 119 | if (1 == $tables[$i]->getVar('table_single')) { |
||
| 120 | $tableSingle = 'single'; |
||
| 121 | } else { |
||
| 122 | $tableSingle = $tableName; |
||
| 123 | } |
||
| 124 | $case[] = $xc->getXcEqualsOperator('$sql ', "'SELECT {$fieldMain} FROM ' . \$xoopsDB->prefix('{$moduleDirname}_{$tableName}') . ' WHERE {$fieldId} = '. \$item_id",'',$t . "\t\t"); |
||
| 125 | $case[] = $xc->getXcEqualsOperator('$result ', '$xoopsDB->query($sql)','',$t . "\t\t"); |
||
| 126 | $case[] = $xc->getXcEqualsOperator('$result_array', '$xoopsDB->fetchArray($result)','',$t . "\t\t"); |
||
| 127 | $case[] = $xc->getXcEqualsOperator("\$item['name']", "\$result_array['{$fieldMain}']",'',$t . "\t\t"); |
||
| 128 | if ($fieldParent) { |
||
| 129 | $case[] = $xc->getXcEqualsOperator("\$item['url'] ", "{$stuModuleDirname}_URL . '/{$tableSingle}.php?{$fieldParent}=' . \$result_array['{$fieldParent}'] . '&{$fieldId}=' . \$item_id",'',$t . "\t\t"); |
||
| 130 | } else { |
||
| 131 | $case[] = $xc->getXcEqualsOperator("\$item['url'] ", "{$stuModuleDirname}_URL . '/{$tableName}.php?{$fieldId}=' . \$item_id",'',$t . "\t\t"); |
||
| 132 | } |
||
| 133 | |||
| 134 | $case[] = $this->getSimpleString('return $item;', $t . "\t\t"); |
||
| 135 | $cases = [ |
||
| 136 | $tableName => $case, |
||
| 137 | ]; |
||
| 138 | $contentSwitch .= $pc->getPhpCodeCaseSwitch($cases, false, false, $t . "\t"); |
||
| 139 | unset($case); |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | $func .= $pc->getPhpCodeSwitch('category', $contentSwitch, $t); |
||
| 144 | $func .= $this->getSimpleString('return null;', $t ); |
||
| 145 | $ret .= $pc->getPhpCodeFunction("{$moduleDirname}_notify_iteminfo", '$category, $item_id', $func); |
||
| 146 | |||
| 147 | return $ret; |
||
| 148 | } |
||
| 168 |