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