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