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 |
||
23 | class ext extends \phpbb\extension\base |
||
24 | { |
||
25 | /** |
||
26 | * Check whether or not the extension can be enabled. |
||
27 | * The current phpBB version should meet or exceed |
||
28 | * the minimum version required by this extension: |
||
29 | * |
||
30 | * Requires phpBB 3.1.3 due to usage of container aware migrations. |
||
31 | * |
||
32 | * @return bool |
||
33 | * @access public |
||
34 | */ |
||
35 | public function is_enableable() |
||
41 | |||
42 | /** |
||
43 | * Overwrite enable_step to enable extension notifications before any included migrations are installed. |
||
44 | * |
||
45 | * @param mixed $old_state State returned by previous call of this method |
||
46 | * |
||
47 | * @return mixed Returns false after last step, otherwise temporary state |
||
48 | * @access public |
||
49 | */ |
||
50 | View Code Duplication | public function enable_step($old_state) |
|
62 | |||
63 | /** |
||
64 | * Overwrite disable_step to disable extension notifications before the extension is disabled. |
||
65 | * |
||
66 | * @param mixed $old_state State returned by previous call of this method |
||
67 | * |
||
68 | * @return mixed Returns false after last step, otherwise temporary state |
||
69 | * @access public |
||
70 | */ |
||
71 | View Code Duplication | public function disable_step($old_state) |
|
83 | |||
84 | /** |
||
85 | * Overwrite purge_step to purge extension notifications before any included and installed migrations are reverted. |
||
86 | * |
||
87 | * @param mixed $old_state State returned by previous call of this method |
||
88 | * |
||
89 | * @return mixed Returns false after last step, otherwise temporary state |
||
90 | * @access public |
||
91 | */ |
||
92 | View Code Duplication | public function purge_step($old_state) |
|
104 | |||
105 | /** |
||
106 | * Notification handler to call notification enable/disable/purge steps |
||
107 | * |
||
108 | * @author VSEphpbb (Matt Friedman) |
||
109 | * @copyright (c) 2014 phpBB Limited <https://www.phpbb.com> |
||
110 | * @license GNU General Public License, version 2 (GPL-2.0) |
||
111 | * |
||
112 | * @param string $step The step (enable, disable, purge) |
||
113 | * @param array $notification_types The notification type names |
||
114 | * |
||
115 | * @return string Return notifications as temporary state |
||
116 | * @access protected |
||
117 | */ |
||
118 | protected function notification_handler($step, $notification_types) |
||
130 | } |
||
131 |