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 |
||
| 16 | class main_module |
||
| 17 | { |
||
| 18 | /** @var \phpbb\cache\driver\driver_interface $cache */ |
||
| 19 | protected $cache; |
||
| 20 | |||
| 21 | /** @var \phpbb\config\config $config */ |
||
| 22 | protected $config; |
||
| 23 | |||
| 24 | /** @var \phpbb\config\db_text $config_text */ |
||
| 25 | protected $config_text; |
||
| 26 | |||
| 27 | /** @var \Symfony\Component\DependencyInjection\ContainerInterface $container */ |
||
| 28 | protected $container; |
||
| 29 | |||
| 30 | /** @var \phpbb\language\language $language */ |
||
| 31 | protected $language; |
||
| 32 | |||
| 33 | /** @var \phpbb\log\log $log */ |
||
| 34 | protected $log; |
||
| 35 | |||
| 36 | /** @var \phpbb\request\request $request */ |
||
| 37 | protected $request; |
||
| 38 | |||
| 39 | /** @var \phpbb\template\template $template */ |
||
| 40 | protected $template; |
||
| 41 | |||
| 42 | /** @var \phpbb\user */ |
||
| 43 | protected $user; |
||
| 44 | |||
| 45 | /** @var array $enabled_sites */ |
||
| 46 | protected $enabled_sites; |
||
| 47 | |||
| 48 | /** @var string $page_title */ |
||
| 49 | public $page_title; |
||
| 50 | |||
| 51 | /** @var string $tpl_name */ |
||
| 52 | public $tpl_name; |
||
| 53 | |||
| 54 | /** @var string $u_action */ |
||
| 55 | public $u_action; |
||
| 56 | |||
| 57 | /** @var array An array of errors */ |
||
| 58 | protected $errors = []; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Constructor |
||
| 62 | * |
||
| 63 | * @throws \Exception |
||
| 64 | */ |
||
| 65 | public function __construct() |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Main ACP module |
||
| 84 | * |
||
| 85 | * @param int $id The module ID (not used) |
||
| 86 | * @param string $mode The module mode (manage|settings) |
||
| 87 | * @throws \Exception |
||
| 88 | */ |
||
| 89 | public function main($id, $mode) |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Add settings template vars to the form |
||
| 119 | */ |
||
| 120 | protected function display_settings() |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Add manage sites template vars to the form |
||
| 133 | * |
||
| 134 | * @throws \Exception |
||
| 135 | */ |
||
| 136 | protected function display_manage() |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Get a list of available sites |
||
| 147 | * |
||
| 148 | * @return array An array of available sites |
||
| 149 | * @throws \Exception |
||
| 150 | */ |
||
| 151 | protected function get_sites() |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Get enabled media sites stored in the database |
||
| 177 | * |
||
| 178 | * @return array An array of enabled sites |
||
| 179 | */ |
||
| 180 | protected function get_enabled_sites() |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Save site managed data to the database |
||
| 193 | */ |
||
| 194 | protected function save_manage() |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Save settings data to the database |
||
| 207 | */ |
||
| 208 | protected function save_settings() |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Purge cached TextFormatter files |
||
| 224 | */ |
||
| 225 | protected function purge_textformatter_cache() |
||
| 230 | |||
| 231 | /** |
||
| 232 | * Purge all MediaEmbed cache files |
||
| 233 | */ |
||
| 234 | protected function purge_mediaembed_cache() |
||
| 262 | } |
||
| 263 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.