| Conditions | 10 |
| Paths | 13 |
| Total Lines | 57 |
| Code Lines | 37 |
| 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); |
||
| 43 | function newbbSinceSelectBox(int $selected = 100): string |
||
| 44 | { |
||
| 45 | $newbbConfig = newbbLoadConfig(); |
||
| 46 | // irmtfan - new method to get user inputs |
||
| 47 | preg_match_all('/-?\d+/', (string) $newbbConfig['since_options'], $match); |
||
| 48 | $select_array = array_unique($match[0]); |
||
| 49 | //$select_array = explode(',', $newbbConfig['since_options']); |
||
| 50 | //$select_array = array_map('trim', $select_array); |
||
| 51 | // irmtfan - if the array is empty do not show selection box |
||
| 52 | if (!$select_array) { |
||
|
|
|||
| 53 | $since = $newbbConfig['since_default']; |
||
| 54 | switch ($since) { |
||
| 55 | case 0: |
||
| 56 | $forum_since = _MD_NEWBB_BEGINNING; |
||
| 57 | break; |
||
| 58 | case 365: |
||
| 59 | $forum_since = _MD_NEWBB_THELASTYEAR; |
||
| 60 | break; |
||
| 61 | default: |
||
| 62 | if ($since > 0) { |
||
| 63 | $forum_since = sprintf(_MD_NEWBB_FROMLASTDAYS, $since); |
||
| 64 | } else { |
||
| 65 | $forum_since = sprintf(_MD_NEWBB_FROMLASTHOURS, abs($since)); |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | return $forum_since; |
||
| 70 | } |
||
| 71 | $forum_selection_since = '<select class="form-control" name="since" id="since">'; |
||
| 72 | // irmtfan no option when no selected value |
||
| 73 | $forum_selection_since .= '<option value="">--------</option>'; |
||
| 74 | foreach ($select_array as $since) { |
||
| 75 | $forum_selection_since .= '<option value="' . $since . '"' . (($selected == $since) ? ' selected="selected"' : '') . '>'; |
||
| 76 | // START irmtfan functional since 0 and 365 |
||
| 77 | switch ($since) { |
||
| 78 | case 0: |
||
| 79 | $forum_selection_since .= _MD_NEWBB_BEGINNING; |
||
| 80 | break; |
||
| 81 | case 365: |
||
| 82 | $forum_selection_since .= _MD_NEWBB_THELASTYEAR; |
||
| 83 | break; |
||
| 84 | default: |
||
| 85 | if ($since > 0) { |
||
| 86 | $forum_selection_since .= sprintf(_MD_NEWBB_FROMLASTDAYS, $since); |
||
| 87 | } else { |
||
| 88 | $forum_selection_since .= sprintf(_MD_NEWBB_FROMLASTHOURS, abs((int)$since)); |
||
| 89 | } |
||
| 90 | } |
||
| 91 | // END irmtfan functional since 0 and 365 |
||
| 92 | $forum_selection_since .= '</option>'; |
||
| 93 | } |
||
| 94 | // irmtfan remove hardcodes |
||
| 95 | //$forum_selection_since .= '<option value="365"'.(($selected === 365) ? ' selected="selected"' : '').'>'._MD_NEWBB_THELASTYEAR.'</option>'; |
||
| 96 | //$forum_selection_since .= '<option value="0"'.(($selected === 0) ? ' selected="selected"' : '').'>'._MD_NEWBB_BEGINNING.'</option>'; |
||
| 97 | $forum_selection_since .= '</select>'; |
||
| 98 | |||
| 99 | return $forum_selection_since; |
||
| 100 | } |
||
| 120 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.