| Conditions | 16 |
| Paths | 2592 |
| Total Lines | 80 |
| Code Lines | 55 |
| 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 declare(strict_types=1); |
||
| 94 | function b_news_archives_edit($options) |
||
| 95 | { |
||
| 96 | global $xoopsDB; |
||
| 97 | $syear = $smonth = $eyear = $emonth = $older = $recent = 0; |
||
| 98 | $selsyear = $selsmonth = $seleyear = $selemonth = 0; |
||
| 99 | $form = ''; |
||
| 100 | |||
| 101 | $selsyear = $options[1]; |
||
| 102 | $selsmonth = $options[2]; |
||
| 103 | $seleyear = $options[3]; |
||
| 104 | $selemonth = $options[4]; |
||
| 105 | |||
| 106 | $tmpstory = new NewsStory(); |
||
| 107 | $tmpstory->getOlderRecentNews($older, $recent); // We are searching for the module's older and more recent article's date |
||
| 108 | |||
| 109 | // Min and max value for the two dates selectors |
||
| 110 | // We are going to use the older news for the starting date |
||
| 111 | $syear = date('Y', $older); |
||
| 112 | $smonth = date('n', $older); |
||
| 113 | $eyear = date('Y', $recent); |
||
| 114 | $emonth = date('n', $recent); |
||
| 115 | // Verify parameters |
||
| 116 | if (0 == $selsyear && 0 == $selsmonth) { |
||
| 117 | $selsyear = $syear; |
||
| 118 | $selsmonth = $smonth; |
||
| 119 | } |
||
| 120 | if (0 == $seleyear && 0 == $selemonth) { |
||
| 121 | $seleyear = $eyear; |
||
| 122 | $selemonth = $emonth; |
||
| 123 | } |
||
| 124 | |||
| 125 | // Sort order ************************************************************* |
||
| 126 | // (0=older first, 1=newer first) |
||
| 127 | $form .= '<b>' . _MB_NEWS_ORDER . "</b> <select name='options[]'>"; |
||
| 128 | $form .= "<option value='0'"; |
||
| 129 | if (0 == $options[0]) { |
||
| 130 | $form .= ' selected'; |
||
| 131 | } |
||
| 132 | $form .= '>' . _MB_NEWS_OLDER_FIRST . "</option>\n"; |
||
| 133 | $form .= "<option value='1'"; |
||
| 134 | if (1 == $options[0]) { |
||
| 135 | $form .= ' selected'; |
||
| 136 | } |
||
| 137 | $form .= '>' . _MB_NEWS_RECENT_FIRST . '</option>'; |
||
| 138 | $form .= "</select>\n"; |
||
| 139 | |||
| 140 | // Starting and ending dates ********************************************** |
||
| 141 | $form .= '<br><br><b>' . _MB_NEWS_STARTING_DATE . '</b><br>'; |
||
| 142 | $form .= _MB_NEWS_CAL_YEAR . " <select name='options[]'>"; |
||
| 143 | for ($i = $syear; $i <= $eyear; ++$i) { |
||
| 144 | $selected = ($i == $selsyear) ? 'selected' : ''; |
||
| 145 | $form .= "<option value='" . $i . "'" . $selected . '>' . $i . '</option>'; |
||
| 146 | } |
||
| 147 | $form .= '</select> ' . _MB_NEWS_CAL_MONTH . " <select name='options[]'>"; |
||
| 148 | for ($i = 1; $i <= 12; ++$i) { |
||
| 149 | $selected = ($i == $selsmonth) ? 'selected' : ''; |
||
| 150 | $form .= "<option value='" . $i . "'" . $selected . '>' . $i . '</option>'; |
||
| 151 | } |
||
| 152 | $form .= '</select>'; |
||
| 153 | |||
| 154 | $form .= '<br><br><b>' . _MB_NEWS_ENDING_DATE . '</b><br>'; |
||
| 155 | $form .= _MB_NEWS_CAL_YEAR . " <select name='options[]'>"; |
||
| 156 | for ($i = $syear; $i <= $eyear; ++$i) { |
||
| 157 | $selected = ($i == $seleyear) ? 'selected' : ''; |
||
| 158 | $form .= "<option value='" . $i . "'" . $selected . '>' . $i . '</option>'; |
||
| 159 | } |
||
| 160 | $form .= '</select> ' . _MB_NEWS_CAL_MONTH . " <select name='options[]'>"; |
||
| 161 | for ($i = 1; $i <= 12; ++$i) { |
||
| 162 | $selected = ($i == $selemonth) ? 'selected' : ''; |
||
| 163 | $form .= "<option value='" . $i . "'" . $selected . '>' . $i . '</option>'; |
||
| 164 | } |
||
| 165 | $form .= '</select>'; |
||
| 166 | |||
| 167 | // Or until today ********************************************************* |
||
| 168 | $form .= '<br>'; |
||
| 169 | $checked = 1 == $options[5] ? ' checked' : ''; |
||
| 170 | $form .= "<input type='checkbox' value='1' name='options[]'" . $checked . '>'; |
||
| 171 | $form .= ' <b>' . _MB_NEWS_UNTIL_TODAY . '</b>'; |
||
| 172 | |||
| 173 | return $form; |
||
| 174 | } |
||
| 188 |