| Conditions | 13 |
| Paths | 4096 |
| Total Lines | 56 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 122 | function b_xoopspartners_edit($options) |
||
| 123 | { |
||
| 124 | if (0 == $options[0]) { //put spaces between partners |
||
| 125 | $chk0no = " checked='checked'"; |
||
| 126 | $chk0yes = ''; |
||
| 127 | } else { |
||
| 128 | $chk0no = ''; |
||
| 129 | $chk0yes = " checked='checked'"; |
||
| 130 | } |
||
| 131 | if (0 == $options[1]) { //fade partners in/out |
||
| 132 | $chk1no = " checked='checked'"; |
||
| 133 | $chk1yes = ''; |
||
| 134 | } else { |
||
| 135 | $chk1no = ''; |
||
| 136 | $chk1yes = " checked='checked'"; |
||
| 137 | } |
||
| 138 | if (0 == $options[2]) { //randomize partners in block |
||
| 139 | $chk2no = " checked='checked'"; |
||
| 140 | $chk2yes = ''; |
||
| 141 | } else { |
||
| 142 | $chk2no = ''; |
||
| 143 | $chk2yes = " checked='checked'"; |
||
| 144 | } |
||
| 145 | $form = |
||
| 146 | "<table style='border-width: 0px;'>\n" . " <tr>\n" . ' <td>' . _MB_XPARTNERS_PSPACE . "</td>\n" . ' <td>' . "<input type='radio' name='options[0]' value='0'{$chk0no}>" . _NO . '' . "<input type='radio' name='options[0]' value='1'{$chk0yes}>" . _YES . '' . " </td>\n" . " </tr>\n" |
||
| 147 | . " <tr>\n" . ' <td>' . _MB_XPARTNERS_FADE . "</td>\n" . ' <td>' . "<input type='radio' name='options[1]' value='0'{$chk1no}>" . _NO . '' . "<input type='radio' name='options[1]' value='1'{$chk1yes}>" . _YES . "</td>\n" . " </tr>\n" . " <tr>\n" . ' <td>' . _MB_XPARTNERS_BRAND |
||
| 148 | . "</td>\n" . ' <td>' . "<input type='radio' name='options[2]' value='0'{$chk2no}>" . _NO . '' . "<input type='radio' name='options[2]' value='1'{$chk2yes}>" . _YES . "</td>\n" . " </tr>\n" . " <tr>\n" . ' <td>' . _MB_XPARTNERS_BLIMIT . "</td>\n" |
||
| 149 | . " <td><input class='txtright' type='number' name='options[3]' size='5' value='{$options[3]}' min='0'></td>\n" . " </tr>\n" . " <tr>\n" . ' <td>' . _MB_XPARTNERS_BSHOW . "</td>\n" . " <td>\n" . " <select size='1' name='options[4]'>\n"; |
||
| 150 | $sel = (1 == $options[4]) ? " selected='selected'" : ''; |
||
| 151 | $form .= " <option value='1'{$sel}>" . _MB_XPARTNERS_IMAGES . "</option>\n"; |
||
| 152 | |||
| 153 | $sel = (2 == $options[4]) ? " selected='selected'" : ''; |
||
| 154 | $form .= " <option value='2'{$sel}>" . _MB_XPARTNERS_TEXT . "</option>\n"; |
||
| 155 | |||
| 156 | $sel = (3 == $options[4]) ? " selected='selected'" : ''; |
||
| 157 | $form .= " <option value='3'{$sel}>" . _MB_XPARTNERS_BOTH . "</option>\n" . " </select>\n" . " </td>\n" . " </tr>\n" . " <tr>\n" . ' <td>' . _MB_XPARTNERS_BSORT . "</td>\n" . " <td>\n" . " <select size='1' name='options[5]'>"; |
||
| 158 | $sel = ('id' === $options[5]) ? " selected='selected'" : ''; |
||
| 159 | $form .= " <option value='id'{$sel}>" . _MB_XPARTNERS_ID . "</option>\n"; |
||
| 160 | |||
| 161 | $sel = ('hits' === $options[5]) ? " selected='selected'" : ''; |
||
| 162 | $form .= " <option value='hits'{$sel}>" . _MB_XPARTNERS_HITS . "</option>\n"; |
||
| 163 | |||
| 164 | $sel = ('title' === $options[5]) ? " selected='selected'" : ''; |
||
| 165 | $form .= " <option value='title'{$sel}>" . _MB_XPARTNERS_TITLE . "</option>\n"; |
||
| 166 | |||
| 167 | $sel = ('weight' === $options[5]) ? " selected='selected'" : ''; |
||
| 168 | $form .= " <option value='weight'{$sel}>" . _MB_XPARTNERS_WEIGHT . "</option>\n" . " </select>\n" . " <select size='1' name='options[6]'>\n"; |
||
| 169 | |||
| 170 | $sel = ('ASC' === $options[6]) ? " selected='selected'" : ''; |
||
| 171 | $form .= " <option value='ASC'{$sel}>" . _MB_XPARTNERS_ASC . "</option>\n"; |
||
| 172 | |||
| 173 | $sel = ('DESC' === $options[6]) ? " selected='selected'" : ''; |
||
| 174 | $form .= " <option value='DESC'{$sel}>" . _MB_XPARTNERS_DESC . "</option>\n" . " </select>\n" . " </td>\n" . " </tr>\n" . " <tr>\n" . ' <td>' . _MB_XPARTNERS_TTL_LENGTH . "</td>\n" |
||
| 175 | . " <td><input type='number' class='txtright' name='options[7]' size='5' value='{$options[7]}' min='0'></td>\n" . " </tr>\n" . " <tr>\n" . "</table>\n"; |
||
| 176 | return $form; |
||
| 177 | } |
||
| 178 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: