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_nemein_wiki_handler_edit extends midcom_baseclasses_components_handler |
||
|
1 ignored issue
–
show
|
|||
| 15 | { |
||
| 16 | /** |
||
| 17 | * The wikipage we're editing |
||
| 18 | * |
||
| 19 | * @var net_nemein_wiki_wikipage |
||
| 20 | */ |
||
| 21 | private $_page = null; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * The Controller of the article used for editing |
||
| 25 | * |
||
| 26 | * @var midcom_helper_datamanager2_controller_simple |
||
| 27 | */ |
||
| 28 | private $_controller = 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 | * Loads and prepares the schema database. |
||
| 39 | * |
||
| 40 | * The operations are done on all available schemas within the DB. |
||
| 41 | */ |
||
| 42 | private function _load_schemadb() |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Internal helper, loads the controller for the current article. Any error triggers a 500. |
||
| 58 | */ |
||
| 59 | View Code Duplication | private function _load_controller() |
|
| 60 | { |
||
| 61 | $this->_load_schemadb(); |
||
| 62 | $this->_controller = midcom_helper_datamanager2_controller::create('simple'); |
||
| 63 | $this->_controller->schemadb =& $this->_schemadb; |
||
| 64 | $this->_controller->set_storage($this->_page); |
||
| 65 | if (! $this->_controller->initialize()) |
||
| 66 | { |
||
| 67 | throw new midcom_error("Failed to initialize a DM2 controller instance for article {$this->_article->id}."); |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Check the edit request |
||
| 73 | * |
||
| 74 | * @param mixed $handler_id The ID of the handler. |
||
| 75 | * @param array $args The argument list. |
||
| 76 | * @param array &$data The local request data. |
||
| 77 | */ |
||
| 78 | public function _handler_edit($handler_id, array $args, array &$data) |
||
| 119 | |||
| 120 | private function add_preview() |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @param mixed $handler_id The ID of the handler. |
||
| 160 | * @param array $args The argument list. |
||
| 161 | * @param array &$data The local request data. |
||
| 162 | */ |
||
| 163 | public function _handler_change($handler_id, array $args, array &$data) |
||
| 179 | } |
||
| 180 |
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.