Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 15 | class statistics extends module_base |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * Allowed columns: Just sum up your options (Exp: left + right = 10) |
||
| 19 | * top 1 |
||
| 20 | * left 2 |
||
| 21 | * center 4 |
||
| 22 | * right 8 |
||
| 23 | * bottom 16 |
||
| 24 | */ |
||
| 25 | public $columns = 10; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Default modulename |
||
| 29 | */ |
||
| 30 | public $name = 'STATISTICS'; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Default module-image: |
||
| 34 | * file must be in "{T_THEME_PATH}/images/portal/" |
||
| 35 | */ |
||
| 36 | public $image_src = 'portal_statistics.png'; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * module-language file |
||
| 40 | * file must be in "language/{$user->lang}/mods/portal/" |
||
| 41 | */ |
||
| 42 | public $language = 'portal_statistics_module'; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * custom acp template |
||
| 46 | * file must be in "adm/style/portal/" |
||
| 47 | */ |
||
| 48 | public $custom_acp_tpl = ''; |
||
| 49 | |||
| 50 | /** @var \phpbb\cache\service */ |
||
| 51 | protected $cache; |
||
| 52 | |||
| 53 | /** @var \phpbb\config\config */ |
||
| 54 | protected $config; |
||
| 55 | |||
| 56 | /** @var \phpbb\db\driver\driver_interface */ |
||
| 57 | protected $db; |
||
| 58 | |||
| 59 | /** @var \phpbb\template\template */ |
||
| 60 | protected $template; |
||
| 61 | |||
| 62 | /** @var \phpbb\user */ |
||
| 63 | protected $user; |
||
| 64 | |||
| 65 | /** @var double Board days */ |
||
| 66 | protected $board_days; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Construct a search object |
||
| 70 | * |
||
| 71 | * @param \phpbb\cache\service $cache phpBB cache system |
||
| 72 | * @param \phpbb\config\config $config phpBB config |
||
| 73 | * @param \phpbb\db\driver\driver_interface $db phpBB database system |
||
| 74 | * @param \phpbb\template\template $template phpBB template |
||
| 75 | * @param \phpbb\user $user phpBB user object |
||
| 76 | */ |
||
| 77 | View Code Duplication | public function __construct($cache, $config, $db, $template, $user) |
|
| 85 | |||
| 86 | /** |
||
| 87 | * {@inheritdoc} |
||
| 88 | */ |
||
| 89 | public function get_template_side($module_id) |
||
| 144 | |||
| 145 | /** |
||
| 146 | * {@inheritdoc} |
||
| 147 | */ |
||
| 148 | public function get_template_acp($module_id) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Get topics count by type |
||
| 158 | * |
||
| 159 | * @return array Topics count array with type in array keys and count |
||
| 160 | * in array values |
||
| 161 | */ |
||
| 162 | public function get_topics_count() |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Get correct average per day on first day. |
||
| 204 | * The per day average will be higher than the total amount. This will |
||
| 205 | * result in incorrect statistics. |
||
| 206 | * |
||
| 207 | * @param int $average Average per day |
||
| 208 | * @param int $total Total value |
||
| 209 | * |
||
| 210 | * @return int Corrected average per day, if correction was necessary |
||
| 211 | */ |
||
| 212 | protected function get_first_day_average($average, $total) |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Get language string for totals |
||
| 219 | * |
||
| 220 | * @param int $total The total value |
||
| 221 | * @param string $language_variable Language variable of the total |
||
| 222 | * @param string $count_language_variable Optional language variable for count |
||
| 223 | * |
||
| 224 | * @return string Language string for total |
||
| 225 | */ |
||
| 226 | protected function get_totals_language($total, $language_variable, $count_language_variable = '') |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Get language variable for averages |
||
| 238 | * |
||
| 239 | * @param int $total The total value |
||
| 240 | * @param string $language_variable Language variable of the total |
||
| 241 | * |
||
| 242 | * @return string Language string for total |
||
| 243 | */ |
||
| 244 | protected function get_average_language($total, $language_variable) |
||
| 248 | } |
||
| 249 |