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 | public function onSave( $settings ) |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @return void |
||
| 135 | */ |
||
| 136 | public function renderFooterScript() |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @return void |
||
| 147 | */ |
||
| 148 | public function renderPage() |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @return void |
||
| 159 | */ |
||
| 160 | public function renderSubmitMetaBox() |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @return void |
||
| 176 | */ |
||
| 177 | public function reset() |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @return array |
||
| 192 | */ |
||
| 193 | protected function getInstructions() |
||
| 199 | |||
| 200 | /** |
||
| 201 | * @return array |
||
| 202 | */ |
||
| 203 | protected function getPostTypes() |
||
| 207 | |||
| 208 | /** |
||
| 209 | * {@inheritdoc} |
||
| 210 | */ |
||
| 211 | View Code Duplication | protected function normalize() |
|
| 224 | |||
| 225 | /** |
||
| 226 | * @param string $name |
||
| 227 | * @param string $parentId |
||
| 228 | * @return string |
||
| 229 | */ |
||
| 230 | protected function normalizeFieldName( $name, array $data, $parentId ) |
||
| 238 | |||
| 239 | /** |
||
| 240 | * @param string $id |
||
| 241 | * @param string $parentId |
||
| 242 | * @return string |
||
| 243 | */ |
||
| 244 | protected function normalizeId( $id, array $data, $parentId ) |
||
| 250 | } |
||
| 251 |