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 |
||
| 9 | class Settings extends MetaBox |
||
| 10 | { |
||
| 11 | const CONDITIONS = [ |
||
| 12 | 'hook', 'is_plugin_active', 'is_plugin_inactive', |
||
| 13 | ]; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var string |
||
| 17 | */ |
||
| 18 | CONST ID = 'pollux-settings'; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | public $hook; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * {@inheritdoc} |
||
| 27 | */ |
||
| 28 | public function init() |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @return void |
||
| 47 | */ |
||
| 48 | public function addPage() |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @return void |
||
| 63 | */ |
||
| 64 | public function addSubmitMetaBox() |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @param string $instruction |
||
| 78 | * @param string $fieldId |
||
| 79 | * @param string $metaboxId |
||
| 80 | * @return string |
||
| 81 | */ |
||
| 82 | public function filterInstruction( $instruction, $fieldId, $metaboxId ) |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @param string $location |
||
| 89 | * @return string |
||
| 90 | */ |
||
| 91 | public function filterRedirectOnSave( $location ) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @return void |
||
| 105 | */ |
||
| 106 | public function register( $metaboxes = [] ) |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @return void |
||
| 121 | */ |
||
| 122 | public function registerSetting() |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @return void |
||
| 129 | */ |
||
| 130 | public function renderFooterScript() |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @return void |
||
| 141 | */ |
||
| 142 | public function renderPage() |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @return void |
||
| 153 | */ |
||
| 154 | public function renderSubmitMetaBox() |
||
| 167 | |||
| 168 | /** |
||
| 169 | * @return void |
||
| 170 | */ |
||
| 171 | public function reset() |
||
| 183 | |||
| 184 | /** |
||
| 185 | * {@inheritdoc} |
||
| 186 | */ |
||
| 187 | View Code Duplication | protected function normalize() |
|
| 200 | |||
| 201 | /** |
||
| 202 | * @param string $name |
||
| 203 | * @param string $parentId |
||
| 204 | * @return string |
||
| 205 | */ |
||
| 206 | protected function normalizeFieldName( $name, array $data, $parentId ) |
||
| 214 | |||
| 215 | /** |
||
| 216 | * @param string $id |
||
| 217 | * @param string $parentId |
||
| 218 | * @return string |
||
| 219 | */ |
||
| 220 | protected function normalizeId( $id, array $data, $parentId ) |
||
| 226 | } |
||
| 227 |