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 |
||
| 14 | class net_nehmer_static_handler_admin extends midcom_baseclasses_components_handler |
||
|
1 ignored issue
–
show
|
|||
| 15 | { |
||
| 16 | /** |
||
| 17 | * The content topic to use |
||
| 18 | * |
||
| 19 | * @var midcom_db_topic |
||
| 20 | */ |
||
| 21 | private $_content_topic = null; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * The article to operate on |
||
| 25 | * |
||
| 26 | * @var midcom_db_article |
||
| 27 | */ |
||
| 28 | private $_article = null; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * The schema database in use, available only while a datamanager is loaded. |
||
| 32 | * |
||
| 33 | * @var Array |
||
| 34 | */ |
||
| 35 | private $_schemadb = null; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Maps the content topic from the request data to local member variables. |
||
| 39 | */ |
||
| 40 | public function _on_initialize() |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Loads and prepares the schema database. |
||
| 47 | * |
||
| 48 | * Special treatment is done for the name field, which is set readonly for non-admins |
||
| 49 | * if the simple_name_handling config option is set. (using an auto-generated urlname based |
||
| 50 | * on the title, if it is missing.) |
||
| 51 | * |
||
| 52 | * The operations are done on all available schemas within the DB. |
||
| 53 | */ |
||
| 54 | View Code Duplication | private function _load_schemadb() |
|
| 66 | |||
| 67 | /** |
||
| 68 | * Internal helper, loads the controller for the current article. Any error triggers a 500. |
||
| 69 | * |
||
| 70 | * @return midcom_helper_datamanager2_controller_simple |
||
| 71 | */ |
||
| 72 | View Code Duplication | private function _load_controller() |
|
| 85 | |||
| 86 | /** |
||
| 87 | * Displays an article edit view. |
||
| 88 | * |
||
| 89 | * @param mixed $handler_id The ID of the handler. |
||
| 90 | * @param array $args The argument list. |
||
| 91 | * @param array &$data The local request data. |
||
| 92 | */ |
||
| 93 | View Code Duplication | public function _handler_edit($handler_id, array $args, array &$data) |
|
| 120 | |||
| 121 | View Code Duplication | public function save_callback(midcom_helper_datamanager2_controller $controller) |
|
| 132 | |||
| 133 | /** |
||
| 134 | * Displays article link delete confirmation |
||
| 135 | * |
||
| 136 | * @param mixed $handler_id The ID of the handler. |
||
| 137 | * @param array $args The argument list. |
||
| 138 | * @param array &$data The local request data. |
||
| 139 | */ |
||
| 140 | View Code Duplication | public function _handler_deletelink($handler_id, array $args, array &$data) |
|
| 163 | |||
| 164 | /** |
||
| 165 | * Displays an article delete confirmation view. |
||
| 166 | * |
||
| 167 | * @param mixed $handler_id The ID of the handler. |
||
| 168 | * @param array $args The argument list. |
||
| 169 | * @param array &$data The local request data. |
||
| 170 | */ |
||
| 171 | View Code Duplication | public function _handler_delete($handler_id, array $args, array &$data) |
|
| 182 | } |
||
| 183 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.