Conditions | 17 |
Paths | 6561 |
Total Lines | 48 |
Code Lines | 20 |
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\Smartfaq; |
||
83 | public function updateTable($table) |
||
84 | { |
||
85 | global $xoopsDB; |
||
86 | |||
87 | $ret = true; |
||
88 | |||
89 | // If table has a structure, create the table |
||
90 | if ($table->getStructure()) { |
||
91 | $ret = $table->createTable() && $ret; |
||
92 | } |
||
93 | |||
94 | // If table is flag for drop, drop it |
||
95 | if ($table->getFlagForDrop) { |
||
96 | $ret = $table->dropTable() && $ret; |
||
97 | } |
||
98 | |||
99 | // If table has data, insert it |
||
100 | if ($table->getData()) { |
||
101 | $ret = $table->addData() && $ret; |
||
102 | } |
||
103 | |||
104 | // If table has new fields to be added, add them |
||
105 | if ($table->getNewFields()) { |
||
106 | $ret = $table->addNewFields() && $ret; |
||
107 | } |
||
108 | |||
109 | // If table has altered field, alter the table |
||
110 | if ($table->getAlteredFields()) { |
||
111 | $ret = $table->alterTable() && $ret; |
||
112 | } |
||
113 | |||
114 | // If table has updated field values, update the table |
||
115 | if ($table->getUpdatedFields()) { |
||
116 | $ret = $table->updateFieldsValues($table) && $ret; |
||
117 | } |
||
118 | |||
119 | // If table has dropped field, alter the table |
||
120 | if ($table->getDroppedFields()) { |
||
121 | $ret = $table->dropFields($table) && $ret; |
||
122 | } |
||
123 | //felix |
||
124 | // If table has updated field values, update the table |
||
125 | if ($table->getUpdatedWhere()) { |
||
126 | $ret = $table->UpdateWhereValues($table) && $ret; |
||
127 | } |
||
128 | |||
129 | return $ret; |
||
130 | } |
||
131 | } |
||
132 |
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state