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() |
||
182 | |||
183 | /** |
||
184 | * @param string $key |
||
185 | * @return array |
||
186 | */ |
||
187 | protected function filterArrayByKey( array $array, $key ) |
||
193 | |||
194 | /** |
||
195 | * @return array |
||
196 | */ |
||
197 | protected function getDefaults() |
||
212 | |||
213 | /** |
||
214 | * {@inheritdoc} |
||
215 | */ |
||
216 | View Code Duplication | protected function normalize() |
|
229 | |||
230 | /** |
||
231 | * @param string $name |
||
232 | * @param string $parentId |
||
233 | * @return string |
||
234 | */ |
||
235 | protected function normalizeFieldName( $name, array $data, $parentId ) |
||
243 | |||
244 | /** |
||
245 | * @param string $id |
||
246 | * @param string $parentId |
||
247 | * @return string |
||
248 | */ |
||
249 | protected function normalizeId( $id, array $data, $parentId ) |
||
255 | } |
||
256 |