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 |
||
| 20 | View Code Duplication | class TicketSelector extends EditorBlock |
|
| 21 | { |
||
| 22 | |||
| 23 | const EDITOR_BLOCK_TYPE = 'ee-event-editor/ticket-editor-container'; |
||
| 24 | |||
| 25 | |||
| 26 | /** |
||
| 27 | * Perform any early setup required by the block |
||
| 28 | * including setting the block type and supported post types |
||
| 29 | * |
||
| 30 | * @return void |
||
| 31 | */ |
||
| 32 | public function initialize() |
||
| 37 | |||
| 38 | |||
| 39 | /** |
||
| 40 | * Registers the Editor Block with WP core; |
||
| 41 | * Returns the registered block type on success, or false on failure. |
||
| 42 | * |
||
| 43 | * @return WP_Block_Type|false |
||
| 44 | */ |
||
| 45 | public function registerBlock() |
||
| 60 | |||
| 61 | |||
| 62 | /** |
||
| 63 | * @return array |
||
| 64 | */ |
||
| 65 | public function getEditorContainer() |
||
| 72 | |||
| 73 | |||
| 74 | /** |
||
| 75 | * @return void |
||
| 76 | */ |
||
| 77 | public function registerScripts() |
||
| 80 | |||
| 81 | |||
| 82 | /** |
||
| 83 | * @return void |
||
| 84 | */ |
||
| 85 | public function registerStyles() |
||
| 88 | |||
| 89 | |||
| 90 | /** |
||
| 91 | * returns the rendered HTML for the block |
||
| 92 | * |
||
| 93 | * @param array $attributes |
||
| 94 | * @return string |
||
| 95 | */ |
||
| 96 | public function renderBlock(array $attributes = array()) |
||
| 100 | } |
||
| 101 |