| Conditions | 8 |
| Paths | 32 |
| Total Lines | 112 |
| Code Lines | 74 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 63 | private function setupSystemArray() |
||
| 64 | { |
||
| 65 | global $txt; |
||
| 66 | |||
| 67 | /* |
||
| 68 | * The system setup array, the order depends on the $txt array of the select name |
||
| 69 | * |
||
| 70 | * 'mod_id' - Only used as information |
||
| 71 | * 'field' - The members field that should be loaded. Please don't forget to add mem. before the field names |
||
| 72 | * 'order' - What is the field name i need to be sort after |
||
| 73 | * 'where' - Here you can add additional where statements |
||
| 74 | * 'output_text' - What should be displayed after the avatar and nickname |
||
| 75 | * - For example if your field is karmaGood 'output_text' => $txt['karma'] . '%karmaGood%'; |
||
| 76 | * 'output_function' - With this you can add to the $row of the query some information. |
||
| 77 | * 'reverse' - On true it change the reverse cause, if not set it will be false :) |
||
| 78 | * 'enabled' - true = mod exists or is possible to use :D |
||
| 79 | * 'error_msg' => $txt['my_error_msg']; You can insert here what kind of error message should appear if the modification not exists =D |
||
| 80 | */ |
||
| 81 | $this->sp_topStatsSystem = array( |
||
| 82 | '0' => array( |
||
| 83 | 'name' => 'Total time logged in', |
||
| 84 | 'field' => 'mem.total_time_logged_in', |
||
| 85 | 'order' => 'mem.total_time_logged_in', |
||
| 86 | 'output_function' => function(&$row) { |
||
| 87 | global $txt; |
||
| 88 | |||
| 89 | // Figure out the days, hours and minutes. |
||
| 90 | $timeDays = floor($row["total_time_logged_in"] / 86400); |
||
| 91 | $timeHours = floor(($row["total_time_logged_in"] % 86400) / 3600); |
||
| 92 | |||
| 93 | // Figure out which things to show... (days, hours, minutes, etc.) |
||
| 94 | $timelogged = ""; |
||
| 95 | if ($timeDays > 0) |
||
| 96 | { |
||
| 97 | $timelogged .= $timeDays . $txt["totalTimeLogged5"]; |
||
| 98 | } |
||
| 99 | |||
| 100 | if ($timeHours > 0) |
||
| 101 | { |
||
| 102 | $timelogged .= $timeHours . $txt["totalTimeLogged6"]; |
||
| 103 | } |
||
| 104 | |||
| 105 | $timelogged .= floor(($row["total_time_logged_in"] % 3600) / 60) . $txt["totalTimeLogged7"]; |
||
| 106 | $row["timelogged"] = $timelogged; |
||
| 107 | }, |
||
| 108 | 'output_text' => ' %timelogged%', |
||
| 109 | 'reverse_sort_asc' => false, |
||
| 110 | 'enabled' => true, |
||
| 111 | ), |
||
| 112 | '1' => array( |
||
| 113 | 'name' => 'Posts', |
||
| 114 | 'field' => 'mem.posts', |
||
| 115 | 'order' => 'mem.posts', |
||
| 116 | 'output_text' => ' %posts% ' . $txt['posts'], |
||
| 117 | 'enabled' => true, |
||
| 118 | ), |
||
| 119 | '2' => array( |
||
| 120 | 'name' => 'Karma Good', |
||
| 121 | 'field' => 'mem.karma_good, mem.karma_bad', |
||
| 122 | 'order' => 'mem.karma_good', |
||
| 123 | 'output_function' => function(&$row) { |
||
| 124 | $row["karma_total"] = $row["karma_good"] - $row["karma_bad"]; |
||
| 125 | }, |
||
| 126 | 'output_text' => (!empty($this->_modSettings['karmaLabel']) ? $this->_modSettings['karmaLabel'] : '') . ($this->_modSettings['karmaMode'] == 1 ? ' %karma_total%' : ' +%karma_good%\-%karma_bad%'), |
||
| 127 | 'enabled' => !empty($this->_modSettings['karmaMode']), |
||
| 128 | 'error_msg' => $txt['sp_karma_is_disabled'], |
||
| 129 | ), |
||
| 130 | '3' => array( |
||
| 131 | 'name' => 'Karma Bad', |
||
| 132 | 'field' => 'mem.karma_good, mem.karma_bad', |
||
| 133 | 'order' => 'mem.karma_bad', |
||
| 134 | 'output_function' => function(&$row) { |
||
| 135 | $row["karma_total"] = $row["karma_good"] - $row["karma_bad"]; |
||
| 136 | }, |
||
| 137 | 'output_text' => (!empty($this->_modSettings['karmaLabel']) ? $this->_modSettings['karmaLabel'] : '') . ($this->_modSettings['karmaMode'] == 1 ? ' %karma_total%' : ' +%karma_good%\-%karma_bad%'), |
||
| 138 | 'enabled' => !empty($this->_modSettings['karmaMode']), |
||
| 139 | 'error_msg' => $txt['sp_karma_is_disabled'], |
||
| 140 | ), |
||
| 141 | '4' => array( |
||
| 142 | 'name' => 'Karma Total', |
||
| 143 | 'field' => 'mem.karma_good, mem.karma_bad', |
||
| 144 | 'order' => 'FLOOR(1000000+karma_good-karma_bad)', |
||
| 145 | 'output_function' => function(&$row) { |
||
| 146 | $row["karma_total"] = $row["karma_good"] - $row["karma_bad"]; |
||
| 147 | }, |
||
| 148 | 'output_text' => $this->_modSettings['karmaLabel'] . ($this->_modSettings['karmaMode'] == 1 ? ' %karma_total%' : ' ±%karma_good%\%karma_bad%'), |
||
| 149 | 'enabled' => !empty($this->_modSettings['karmaMode']), |
||
| 150 | 'error_msg' => $txt['sp_karma_is_disabled'], |
||
| 151 | ), |
||
| 152 | '5' => array( |
||
| 153 | 'name' => 'Likes Received/Given', |
||
| 154 | 'field' => 'mem.likes_received', |
||
| 155 | 'order' => 'mem.likes_received', |
||
| 156 | 'output_text' => '%likes_received% ' . $txt['sp_topStatsMember_Likes_Received'], |
||
| 157 | 'enabled' => !empty($this->_modSettings['likes_enabled']), |
||
| 158 | 'error_msg' => $txt['sp_likes_is_disabled'], |
||
| 159 | ), |
||
| 160 | '6' => array( |
||
| 161 | 'name' => 'Likes Given', |
||
| 162 | 'field' => 'mem.likes_given', |
||
| 163 | 'order' => 'mem.likes_given', |
||
| 164 | 'output_text' => '%likes_given% ' . $txt['sp_topStatsMember_Likes_Given'], |
||
| 165 | 'enabled' => !empty($this->_modSettings['likes_enabled']), |
||
| 166 | 'error_msg' => $txt['sp_likes_is_disabled'], |
||
| 167 | ), |
||
| 168 | '7' => array( |
||
| 169 | 'name' => 'Likes Totals', |
||
| 170 | 'field' => 'mem.likes_received, mem.likes_given', |
||
| 171 | 'order' => 'mem.likes_received', |
||
| 172 | 'output_text' => $txt['sp_topStatsMember_Likes_Received'] . ': %likes_received% / ' . $txt['sp_topStatsMember_Likes_Given'] . ': %likes_given%', |
||
| 173 | 'enabled' => !empty($this->_modSettings['likes_enabled']), |
||
| 174 | 'error_msg' => $txt['sp_likes_is_disabled'], |
||
| 175 | ), |
||
| 429 |