| Conditions | 14 |
| Paths | 84 |
| Total Lines | 118 |
| Code Lines | 50 |
| 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 |
||
| 58 | function template_memberlist() |
||
| 59 | { |
||
| 60 | global $context, $txt; |
||
| 61 | |||
| 62 | echo ' |
||
| 63 | <div id="memberlist"> |
||
| 64 | <h2 class="category_header"> |
||
| 65 | <span class="floatleft">', $txt['members_list'], '</span>'; |
||
| 66 | |||
| 67 | if (!empty($context['letter_links'])) |
||
| 68 | { |
||
| 69 | echo ' |
||
| 70 | <span class="floatright letter_links">', $context['letter_links'], '</span>'; |
||
| 71 | } |
||
| 72 | |||
| 73 | echo ' |
||
| 74 | </h2> |
||
| 75 | <div class="mlist_container"> |
||
| 76 | <ul class="mlist"> |
||
| 77 | <li class="mlist_header">'; |
||
| 78 | |||
| 79 | // Display each of the column headers of the table. |
||
| 80 | foreach ($context['columns'] as $key => $column) |
||
| 81 | { |
||
| 82 | $sorticon = match ($key) |
||
| 83 | { |
||
| 84 | 'posts', 'date_registered' => 'numeric', |
||
| 85 | default => 'alpha', |
||
| 86 | }; |
||
| 87 | |||
| 88 | // This is a selected column, so underline it or some such. |
||
| 89 | if ($column['selected']) |
||
| 90 | { |
||
| 91 | echo ' |
||
| 92 | <div class="' . $column['class'] . '"> |
||
| 93 | <a href="' . $column['href'] . '">' . $column['label'] . '<i class="icon icon-small i-sort-' . $sorticon . '-' . $context['sort_direction'] . '"></i></a> |
||
| 94 | </div>'; |
||
| 95 | } |
||
| 96 | // This is just some column... show the link and be done with it. |
||
| 97 | else |
||
| 98 | { |
||
| 99 | echo ' |
||
| 100 | <div class="' . $column['class'] . '"> |
||
| 101 | ', $column['link'], ' |
||
| 102 | </div>'; |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | echo ' |
||
| 107 | </li>'; |
||
| 108 | |||
| 109 | // Assuming there are members loop through each one displaying their data. |
||
| 110 | $alternate = true; |
||
| 111 | if (!empty($context['members'])) |
||
| 112 | { |
||
| 113 | foreach ($context['members'] as $member) |
||
| 114 | { |
||
| 115 | if (!empty($member['sort_letter'])) |
||
| 116 | { |
||
| 117 | echo ' |
||
| 118 | <li class="letter_row" id="letter', $member['sort_letter'], '"> |
||
| 119 | <h3>', $member['sort_letter'], '</h3> |
||
| 120 | </li>'; |
||
| 121 | } |
||
| 122 | |||
| 123 | echo ' |
||
| 124 | <li class="', $alternate ? 'alternate_' : 'standard_', 'row">'; |
||
| 125 | |||
| 126 | foreach ($context['columns'] as $column => $values) |
||
| 127 | { |
||
| 128 | if (isset($member[$column])) |
||
| 129 | { |
||
| 130 | echo ' |
||
| 131 | <div class="' . $values['class'] . '">'; |
||
| 132 | |||
| 133 | if ($column === 'online') |
||
| 134 | { |
||
| 135 | echo template_member_online($member); |
||
| 136 | } |
||
| 137 | elseif ($column === 'email_address') |
||
| 138 | { |
||
| 139 | echo template_member_email($member); |
||
| 140 | } |
||
| 141 | else |
||
| 142 | { |
||
| 143 | echo ' |
||
| 144 | ', $member[$column]; |
||
| 145 | } |
||
| 146 | |||
| 147 | echo ' |
||
| 148 | </div>'; |
||
| 149 | } |
||
| 150 | // Any custom fields on display? |
||
| 151 | elseif (!empty($context['custom_profile_fields']['columns']) && isset($context['custom_profile_fields']['columns'][$column])) |
||
| 152 | { |
||
| 153 | echo ' |
||
| 154 | <div class="' . $values['class'] . '">', $member['options'][substr($column, 5)], '</div>'; |
||
| 155 | } |
||
| 156 | } |
||
| 157 | |||
| 158 | echo ' |
||
| 159 | </li>'; |
||
| 160 | |||
| 161 | $alternate = !$alternate; |
||
|
|
|||
| 162 | } |
||
| 163 | |||
| 164 | echo ' |
||
| 165 | </ul> |
||
| 166 | </div>'; |
||
| 167 | } |
||
| 168 | // No members? |
||
| 169 | else |
||
| 170 | { |
||
| 171 | echo ' |
||
| 172 | </ul> |
||
| 173 | </div> |
||
| 174 | <div class="infobox"> |
||
| 175 | ', $txt['find_no_results'], ' |
||
| 176 | </div>'; |
||
| 191 |