| Conditions | 13 |
| Paths | 4096 |
| Total Lines | 107 |
| Code Lines | 94 |
| 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 |
||
| 110 | function b_xoopspartners_edit($options) |
||
| 111 | { |
||
| 112 | if (0 == $options[0]) { //put spaces between partners |
||
| 113 | $chk0no = " checked"; |
||
| 114 | $chk0yes = ''; |
||
| 115 | } else { |
||
| 116 | $chk0no = ''; |
||
| 117 | $chk0yes = " checked"; |
||
| 118 | } |
||
| 119 | if (0 == $options[1]) { //fade partners in/out |
||
| 120 | $chk1no = " checked"; |
||
| 121 | $chk1yes = ''; |
||
| 122 | } else { |
||
| 123 | $chk1no = ''; |
||
| 124 | $chk1yes = " checked"; |
||
| 125 | } |
||
| 126 | if (0 == $options[2]) { //randomize partners in block |
||
| 127 | $chk2no = " checked"; |
||
| 128 | $chk2yes = ''; |
||
| 129 | } else { |
||
| 130 | $chk2no = ''; |
||
| 131 | $chk2yes = " checked"; |
||
| 132 | } |
||
| 133 | $form = "<table class='bnone'>\n" |
||
| 134 | . " <tr>\n" |
||
| 135 | . " <td>" . _MB_XOOPSPARTNERS_PSPACE . "</td>\n" |
||
| 136 | . " <td>" |
||
| 137 | . "<input type='radio' name='options[0]' id ='options0_0' value='0'{$chk0no}>" |
||
| 138 | . "<label for='options0_0'>" . _NO . "</label> " |
||
| 139 | . "<input type='radio' name='options[0]' id ='options0_1' value='1'{$chk0yes}>" |
||
| 140 | . "<label for='options0_1'>" . _YES . "</label>" |
||
| 141 | . "</td>\n" |
||
| 142 | . " </tr>\n" |
||
| 143 | . " <tr>\n" |
||
| 144 | . " <td>" . _MB_XOOPSPARTNERS_FADE . "</td>\n" |
||
| 145 | . " <td>" |
||
| 146 | . "<input type='radio' name='options[1]' id='options1_0' value='0'{$chk1no}>" . _NO |
||
| 147 | . "<label for='options1_0'>" . _NO . "</label> " |
||
| 148 | . "<input type='radio' name='options[1]' id='options1_1' value='1'{$chk1yes}>" . _YES |
||
| 149 | . "<label for='options1_1'>" . _YES . "</label>" |
||
| 150 | . "</td>\n" |
||
| 151 | . " </tr>\n" |
||
| 152 | . " <tr>\n" |
||
| 153 | . " <td>" . _MB_XOOPSPARTNERS_BRAND . "</td>\n" |
||
| 154 | . " <td>" |
||
| 155 | . "<input type='radio' name='options[2]' id='option2_0' value='0'{$chk2no}>" . _NO |
||
| 156 | . "<label for='options2_0'>" . _NO . "</label>" |
||
| 157 | . "<input type='radio' name='options[2]' id='options2_1' value='1'{$chk2yes}>" . _YES |
||
| 158 | . "<label for='options2_1'>" . _YES . "</label>" |
||
| 159 | . "</td>\n" |
||
| 160 | . " </tr>\n" |
||
| 161 | . " <tr>\n" |
||
| 162 | . " <td>" . _MB_XOOPSPARTNERS_BLIMIT . "</td>\n" |
||
| 163 | . " <td><input class='right' type='number' name='options[3]' size='5' value='{$options[3]}' min='0'></td>\n" |
||
| 164 | . " </tr>\n" |
||
| 165 | . " <tr>\n" |
||
| 166 | . ' <td>' . _MB_XOOPSPARTNERS_BSHOW . "</td>\n" |
||
| 167 | . " <td>\n" |
||
| 168 | . " <select size='1' name='options[4]'>\n"; |
||
| 169 | $sel = (1 == $options[4]) ? " selected" : ''; |
||
| 170 | $form .= " <option value='1'{$sel}>" . _MB_XOOPSPARTNERS_IMAGES . "</option>\n"; |
||
| 171 | |||
| 172 | $sel = (2 == $options[4]) ? " selected" : ''; |
||
| 173 | $form .= " <option value='2'{$sel}>" . _MB_XOOPSPARTNERS_TEXT . "</option>\n"; |
||
| 174 | |||
| 175 | $sel = (3 == $options[4]) ? " selected" : ''; |
||
| 176 | $form .= " <option value='3'{$sel}>" . _MB_XOOPSPARTNERS_BOTH . "</option>\n" |
||
| 177 | . " </select>\n" |
||
| 178 | . " </td>\n" |
||
| 179 | . " </tr>\n" |
||
| 180 | . " <tr>\n" |
||
| 181 | . " <td>" . _MB_XOOPSPARTNERS_BSORT . "</td>\n" |
||
| 182 | . " <td>\n" |
||
| 183 | . " <select size='1' name='options[5]'>\n"; |
||
| 184 | |||
| 185 | $sel = ('id' === $options[5]) ? " selected" : ''; |
||
| 186 | $form .= " <option value='id'{$sel}>" . _MB_XOOPSPARTNERS_ID . "</option>\n"; |
||
| 187 | |||
| 188 | $sel = ('hits' === $options[5]) ? " selected" : ''; |
||
| 189 | $form .= " <option value='hits'{$sel}>" . _MB_XOOPSPARTNERS_HITS . "</option>\n"; |
||
| 190 | |||
| 191 | $sel = ('title' === $options[5]) ? " selected" : ''; |
||
| 192 | $form .= " <option value='title'{$sel}>" . _MB_XOOPSPARTNERS_TITLE . "</option>\n"; |
||
| 193 | |||
| 194 | $sel = ('weight' === $options[5]) ? " selected" : ''; |
||
| 195 | $form .= " <option value='weight'{$sel}>" . _MB_XOOPSPARTNERS_WEIGHT . "</option>\n" |
||
| 196 | . " </select>\n" |
||
| 197 | . " <select size='1' name='options[6]'>\n"; |
||
| 198 | |||
| 199 | $sel = ('ASC' === $options[6]) ? " selected" : ''; |
||
| 200 | $form .= " <option value='ASC'{$sel}>" . _MB_XOOPSPARTNERS_ASC . "</option>\n"; |
||
| 201 | |||
| 202 | $sel = ('DESC' === $options[6]) ? " selected" : ''; |
||
| 203 | $form .= " <option value='DESC'{$sel}>" . _MB_XOOPSPARTNERS_DESC . "</option>\n" |
||
| 204 | . " </select>\n" |
||
| 205 | . " </td>\n" |
||
| 206 | . " </tr>\n" |
||
| 207 | . " <tr>\n" |
||
| 208 | . ' <td>' . _MB_XOOPSPARTNERS_TTL_LENGTH . "</td>\n" |
||
| 209 | . " <td>" |
||
| 210 | . "<input type='number' class='right' name='options[7]' size='5' value='{$options[7]}' min='0'>" |
||
| 211 | . "</td>\n" |
||
| 212 | . " </tr>\n" |
||
| 213 | . " <tr>\n" |
||
| 214 | . "</table>\n"; |
||
| 215 | return $form; |
||
| 216 | } |
||
| 217 |
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: