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 |
||
| 18 | class admin_helper |
||
| 19 | { |
||
| 20 | /** @var \phpbb\user */ |
||
| 21 | protected $user; |
||
| 22 | |||
| 23 | /** @var \phpbb\language\language */ |
||
| 24 | protected $language; |
||
| 25 | |||
| 26 | /** @var \phpbb\template\template */ |
||
| 27 | protected $template; |
||
| 28 | |||
| 29 | /** @var \phpbb\log\log */ |
||
| 30 | protected $log; |
||
| 31 | |||
| 32 | /** @var \phpbb\ads\location\manager */ |
||
| 33 | protected $location_manager; |
||
| 34 | |||
| 35 | /** @var string root_path */ |
||
| 36 | protected $root_path; |
||
| 37 | |||
| 38 | /** @var string php_ext */ |
||
| 39 | protected $php_ext; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Constructor |
||
| 43 | * |
||
| 44 | * @param \phpbb\user $user User object |
||
| 45 | * @param \phpbb\language\language $language Language object |
||
| 46 | * @param \phpbb\template\template $template Template object |
||
| 47 | * @param \phpbb\log\log $log The phpBB log system |
||
| 48 | * @param \phpbb\ads\location\manager $location_manager Template location manager object |
||
| 49 | * @param string $root_path phpBB root path |
||
| 50 | * @param string $php_ext PHP extension |
||
| 51 | */ |
||
| 52 | 12 | View Code Duplication | public function __construct(\phpbb\user $user, \phpbb\language\language $language, \phpbb\template\template $template, \phpbb\log\log $log, \phpbb\ads\location\manager $location_manager, $root_path, $php_ext) |
| 62 | |||
| 63 | /** |
||
| 64 | * Assign ad data for ACP form template. |
||
| 65 | * |
||
| 66 | * @param array $data Ad data |
||
| 67 | * @param array $errors Validation errors |
||
| 68 | */ |
||
| 69 | 2 | public function assign_data($data, $errors) |
|
| 89 | |||
| 90 | 5 | /** |
|
| 91 | 5 | * Assign template locations data to the template. |
|
| 92 | 5 | * |
|
| 93 | 5 | * @param mixed $ad_locations The form data or nothing. |
|
| 94 | 5 | * @return void |
|
| 95 | 5 | */ |
|
| 96 | 5 | public function assign_locations($ad_locations = false) |
|
| 108 | 3 | ||
| 109 | 3 | /** |
|
| 110 | 3 | * Log action |
|
| 111 | 3 | * |
|
| 112 | * @param string $action Performed action in uppercase |
||
| 113 | * @param string $ad_name Advertisement name |
||
| 114 | * @return void |
||
| 115 | */ |
||
| 116 | public function log($action, $ad_name) |
||
| 120 | 1 | ||
| 121 | /** |
||
| 122 | 1 | * Get "Find username" URL to easily look for ad owner. |
|
| 123 | 1 | * |
|
| 124 | * @return string Find username URL |
||
| 125 | 1 | */ |
|
| 126 | public function get_find_username_link() |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Is an ad expired? |
||
| 133 | * |
||
| 134 | * @param array $row Advertisement data |
||
| 135 | * @return bool True if expired, false otherwise |
||
| 136 | */ |
||
| 137 | 5 | public function is_expired($row) |
|
| 156 | |||
| 157 | /** |
||
| 158 | * Prepare ad owner for display. Method takes user_id |
||
| 159 | 5 | * of the ad owner and returns his/her username. |
|
| 160 | * |
||
| 161 | 5 | * @param int $ad_owner User ID |
|
| 162 | 5 | * @return string Username belonging to $ad_owner. |
|
| 163 | */ |
||
| 164 | protected function prepare_ad_owner($ad_owner) |
||
| 180 | } |
||
| 181 |