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 |
||
21 | class main_listener implements EventSubscriberInterface |
||
22 | { |
||
23 | /** @var \phpbb\template\template */ |
||
24 | protected $template; |
||
25 | |||
26 | /** @var \phpbb\user */ |
||
27 | protected $user; |
||
28 | |||
29 | /** @var \phpbb\config\db_text */ |
||
30 | protected $config_text; |
||
31 | |||
32 | /** @var \phpbb\config\config */ |
||
33 | protected $config; |
||
34 | |||
35 | /** @var \phpbb\ads\ad\manager */ |
||
36 | protected $manager; |
||
37 | |||
38 | /** @var \phpbb\ads\location\manager */ |
||
39 | protected $location_manager; |
||
40 | |||
41 | /** @var \phpbb\controller\helper */ |
||
42 | protected $controller_helper; |
||
43 | |||
44 | /** @var bool Can the current user view ads? */ |
||
45 | protected $can_view_ads; |
||
46 | |||
47 | /** |
||
48 | * {@inheritdoc} |
||
49 | */ |
||
50 | 1 | public static function getSubscribedEvents() |
|
60 | |||
61 | /** |
||
62 | * Constructor |
||
63 | * |
||
64 | * @param \phpbb\template\template $template Template object |
||
65 | * @param \phpbb\user $user User object |
||
66 | * @param \phpbb\config\db_text $config_text Config text object |
||
67 | * @param \phpbb\config\config $config Config object |
||
68 | * @param \phpbb\ads\ad\manager $manager Advertisement manager object |
||
69 | * @param \phpbb\ads\location\manager $location_manager Template location manager object |
||
70 | * @param \phpbb\controller\helper $controller_helper Controller helper object |
||
71 | */ |
||
72 | 24 | View Code Duplication | public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\config\db_text $config_text, \phpbb\config\config $config, \phpbb\ads\ad\manager $manager, \phpbb\ads\location\manager $location_manager, \phpbb\controller\helper $controller_helper) |
82 | |||
83 | /** |
||
84 | * Wire up u_phpbb_ads permission |
||
85 | * |
||
86 | * @param \phpbb\event\data $event The event object |
||
87 | * @return void |
||
88 | */ |
||
89 | 1 | public function set_permissions($event) |
|
93 | |||
94 | /** |
||
95 | * Load common language file during user setup |
||
96 | * |
||
97 | * @param \phpbb\event\data $event The event object |
||
98 | * @return void |
||
99 | */ |
||
100 | 1 | public function load_language_on_setup($event) |
|
109 | |||
110 | /** |
||
111 | * Displays advertisements |
||
112 | * |
||
113 | * @return void |
||
114 | */ |
||
115 | 6 | public function setup_ads() |
|
135 | |||
136 | /** |
||
137 | * Display Ad blocker friendly message if allowed |
||
138 | * |
||
139 | * @return void |
||
140 | */ |
||
141 | 6 | public function adblocker() |
|
148 | |||
149 | /** |
||
150 | * Add click tracking template variables |
||
151 | * |
||
152 | * @return void |
||
153 | */ |
||
154 | 2 | public function clicks() |
|
164 | |||
165 | /** |
||
166 | * Prepare views counter template |
||
167 | * |
||
168 | * @param array $ad_ids List of ads that will be displayed on current request's page |
||
169 | * @return void |
||
170 | */ |
||
171 | 3 | protected function views($ad_ids) |
|
181 | |||
182 | /** |
||
183 | * Disable XSS Protection |
||
184 | * In Chrome browsers, previewing an Ad Code with javascript can |
||
185 | * be blocked, due to a false positive where Chrome thinks the |
||
186 | * javascript is an XSS injection. This will temporarily disable |
||
187 | * XSS protection in chrome while managing ads in the ACP. |
||
188 | * |
||
189 | * @param \phpbb\event\data $event The event object |
||
190 | */ |
||
191 | 6 | public function disable_xss_protection($event) |
|
199 | |||
200 | /** |
||
201 | * Remove ad owner when deleting user(s) |
||
202 | * |
||
203 | * @param \phpbb\event\data $event The event object |
||
204 | * @return void |
||
205 | */ |
||
206 | 1 | public function remove_ad_owner($event) |
|
210 | |||
211 | /** |
||
212 | * User can view ads only if they are not in a group that has ads hidden |
||
213 | * |
||
214 | * @return bool true if the user is not in a group with ads hidden, false if they are |
||
215 | */ |
||
216 | 9 | protected function can_view_ads() |
|
228 | } |
||
229 |