Conditions | 10 |
Paths | 13 |
Total Lines | 58 |
Code Lines | 38 |
Lines | 12 |
Ratio | 20.69 % |
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 |
||
47 | function newbbSinceSelectBox($selected = 100) |
||
48 | { |
||
49 | $newbbConfig = newbbLoadConfig(); |
||
50 | // irmtfan - new method to get user inputs |
||
51 | preg_match_all('/-?\d+/', $newbbConfig['since_options'], $match); |
||
52 | $select_array = array_unique($match[0]); |
||
53 | //$select_array = explode(',', $newbbConfig['since_options']); |
||
54 | //$select_array = array_map('trim', $select_array); |
||
55 | // irmtfan - if the array is empty do not show selection box |
||
56 | if (!(bool)$select_array) { |
||
57 | $since = $newbbConfig['since_default']; |
||
58 | switch ($since) { |
||
59 | case 0: |
||
60 | $forum_since = _MD_NEWBB_BEGINNING; |
||
61 | break; |
||
62 | case 365: |
||
63 | $forum_since = _MD_NEWBB_THELASTYEAR; |
||
64 | break; |
||
65 | View Code Duplication | default: |
|
66 | if ($since > 0) { |
||
67 | $forum_since = sprintf(_MD_NEWBB_FROMLASTDAYS, $since); |
||
68 | } else { |
||
69 | $forum_since = sprintf(_MD_NEWBB_FROMLASTHOURS, abs($since)); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | return $forum_since; |
||
74 | } |
||
75 | $forum_selection_since = '<select class="form-control" name="since" id="since">'; |
||
76 | // irmtfan no option when no selected value |
||
77 | $forum_selection_since .= '<option value="">--------</option>'; |
||
78 | foreach ($select_array as $since) { |
||
79 | $forum_selection_since .= '<option value="' . $since . '"' . (($selected == $since) ? ' selected="selected"' : '') . '>'; |
||
80 | // START irmtfan functional since 0 and 365 |
||
81 | switch ($since) { |
||
82 | case 0: |
||
83 | $forum_selection_since .= _MD_NEWBB_BEGINNING; |
||
84 | break; |
||
85 | case 365: |
||
86 | $forum_selection_since .= _MD_NEWBB_THELASTYEAR; |
||
87 | break; |
||
88 | View Code Duplication | default: |
|
89 | if ($since > 0) { |
||
90 | $forum_selection_since .= sprintf(_MD_NEWBB_FROMLASTDAYS, $since); |
||
91 | } else { |
||
92 | $forum_selection_since .= sprintf(_MD_NEWBB_FROMLASTHOURS, abs($since)); |
||
93 | } |
||
94 | } |
||
95 | // END irmtfan functional since 0 and 365 |
||
96 | $forum_selection_since .= '</option>'; |
||
97 | } |
||
98 | // irmtfan remove hardcodes |
||
99 | //$forum_selection_since .= '<option value="365"'.(($selected === 365) ? ' selected="selected"' : '').'>'._MD_NEWBB_THELASTYEAR.'</option>'; |
||
100 | //$forum_selection_since .= '<option value="0"'.(($selected === 0) ? ' selected="selected"' : '').'>'._MD_NEWBB_BEGINNING.'</option>'; |
||
101 | $forum_selection_since .= '</select>'; |
||
102 | |||
103 | return $forum_selection_since; |
||
104 | } |
||
105 | |||
121 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.