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 |
||
| 17 | class ext extends \phpbb\extension\base |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * Enable extension if requirements are met |
||
| 21 | * |
||
| 22 | * @return bool |
||
| 23 | * @aceess public |
||
| 24 | */ |
||
| 25 | public function is_enableable() |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Single enable step that installs any included migrations |
||
| 47 | * |
||
| 48 | * @param mixed $old_state State returned by previous call of this method |
||
| 49 | * @return mixed Returns false after last step, otherwise temporary state |
||
| 50 | */ |
||
| 51 | View Code Duplication | public function enable_step($old_state) |
|
| 76 | |||
| 77 | /** |
||
| 78 | * Single disable step that does nothing |
||
| 79 | * |
||
| 80 | * @param mixed $old_state State returned by previous call of this method |
||
| 81 | * @return mixed Returns false after last step, otherwise temporary state |
||
| 82 | */ |
||
| 83 | View Code Duplication | public function disable_step($old_state) |
|
| 108 | |||
| 109 | /** |
||
| 110 | * Single purge step that reverts any included and installed migrations |
||
| 111 | * |
||
| 112 | * @param mixed $old_state State returned by previous call of this method |
||
| 113 | * @return mixed Returns false after last step, otherwise temporary state |
||
| 114 | */ |
||
| 115 | View Code Duplication | public function purge_step($old_state) |
|
| 140 | |||
| 141 | /** |
||
| 142 | * Notification handler to call notification enable/disable/purge steps |
||
| 143 | * |
||
| 144 | * @author VSEphpbb (Matt Friedman) |
||
| 145 | * @copyright (c) 2014 phpBB Limited <https://www.phpbb.com> |
||
| 146 | * @license GNU General Public License, version 2 (GPL-2.0) |
||
| 147 | * @param string $step The step (enable, disable, purge) |
||
| 148 | * @param array $notification_types The notification type names |
||
| 149 | * @return string Return notifications as temporary state |
||
| 150 | * @access protected |
||
| 151 | */ |
||
| 152 | protected function notification_handler($step, $notification_types) |
||
| 163 | } |
||
| 164 |