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 donation 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 = 31; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Default modulename |
||
| 29 | */ |
||
| 30 | public $name = 'DONATION'; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Default module-image: |
||
| 34 | * file must be in "{T_THEME_PATH}/images/portal/" |
||
| 35 | */ |
||
| 36 | public $image_src = 'portal_donation.png'; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * module-language file |
||
| 40 | * file must be in "language/{$user->lang}/mods/portal/" |
||
| 41 | */ |
||
| 42 | public $language = 'portal_donation_module'; |
||
| 43 | |||
| 44 | /** @var \phpbb\config\config */ |
||
| 45 | protected $config; |
||
| 46 | |||
| 47 | /** @var \phpbb\request\request_interface */ |
||
| 48 | protected $request; |
||
| 49 | |||
| 50 | /** @var \phpbb\template\template */ |
||
| 51 | protected $template; |
||
| 52 | |||
| 53 | /** @var \phpbb\user */ |
||
| 54 | protected $user; |
||
| 55 | |||
| 56 | /** @var \board3\portal\includes\modules_helper */ |
||
| 57 | protected $helper; |
||
| 58 | |||
| 59 | /** @var array List of currencies supported in donations */ |
||
| 60 | protected $currencies = array( |
||
| 61 | 'AUD', |
||
| 62 | 'CAD', |
||
| 63 | 'CZK', |
||
| 64 | 'DKK', |
||
| 65 | 'HKD', |
||
| 66 | 'HUF', |
||
| 67 | 'NZD', |
||
| 68 | 'NOK', |
||
| 69 | 'PLN', |
||
| 70 | 'GBP', |
||
| 71 | 'SGD', |
||
| 72 | 'SEK', |
||
| 73 | 'CHF', |
||
| 74 | 'JPY', |
||
| 75 | 'USD', |
||
| 76 | 'EUR', |
||
| 77 | 'MXN', |
||
| 78 | 'ILS', |
||
| 79 | ); |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Construct a donation module object |
||
| 83 | * |
||
| 84 | * @param \phpbb\config\config $config phpBB config |
||
| 85 | * @param \phpbb\request\request_interface $request Request |
||
| 86 | * @param \phpbb\template\template $template phpBB template |
||
| 87 | * @param \phpbb\user $user phpBB user object |
||
| 88 | * @param \board3\portal\includes\modules_helper $helper Board3 Portal modules helper |
||
| 89 | */ |
||
| 90 | 43 | public function __construct($config, $request, $template, $user, $helper) |
|
| 98 | |||
| 99 | /** |
||
| 100 | * {@inheritdoc} |
||
| 101 | */ |
||
| 102 | View Code Duplication | public function get_template_center($module_id) |
|
| 113 | |||
| 114 | /** |
||
| 115 | * {@inheritdoc} |
||
| 116 | */ |
||
| 117 | View Code Duplication | public function get_template_side($module_id) |
|
| 128 | |||
| 129 | /** |
||
| 130 | * {@inheritdoc} |
||
| 131 | */ |
||
| 132 | public function get_template_acp($module_id) |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Build currency select for block name |
||
| 147 | * |
||
| 148 | * @param int $module_id Module ID |
||
| 149 | * @param string $block_name Name of template block |
||
| 150 | * @param bool $short Whether short ISO titles should be used |
||
| 151 | */ |
||
| 152 | protected function build_currency_select($module_id, $block_name, $short = false) |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Create select box for attachment filetype |
||
| 166 | * |
||
| 167 | * @param mixed $value Value of input |
||
| 168 | * @param string $key Key name |
||
| 169 | * @param int $module_id Module ID |
||
| 170 | * |
||
| 171 | * @return string Forum select box HTML |
||
| 172 | */ |
||
| 173 | public function select_currency($value, $key, $module_id) |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Save currency setting |
||
| 194 | * |
||
| 195 | * @param string $key |
||
| 196 | * @param int $module_id |
||
| 197 | */ |
||
| 198 | public function save_currency($key, $module_id) |
||
| 202 | |||
| 203 | /** |
||
| 204 | * {@inheritdoc} |
||
| 205 | */ |
||
| 206 | 1 | public function install($module_id) |
|
| 213 | |||
| 214 | /** |
||
| 215 | * {@inheritdoc} |
||
| 216 | */ |
||
| 217 | 1 | View Code Duplication | public function uninstall($module_id, $db) |
| 228 | } |
||
| 229 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.