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 |
||
22 | abstract class BlockAssetManager extends AssetManager implements BlockAssetManagerInterface |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * @var string $editor_script_handle |
||
27 | */ |
||
28 | private $editor_script_handle; |
||
29 | |||
30 | /** |
||
31 | * @var string $editor_style_handle |
||
32 | */ |
||
33 | private $editor_style_handle; |
||
34 | |||
35 | /** |
||
36 | * @var string $script_handle |
||
37 | */ |
||
38 | private $script_handle; |
||
39 | |||
40 | /** |
||
41 | * @var string $style_handle |
||
42 | */ |
||
43 | private $style_handle; |
||
44 | |||
45 | |||
46 | /** |
||
47 | * @return string |
||
48 | */ |
||
49 | public function getEditorScriptHandle() |
||
53 | |||
54 | |||
55 | /** |
||
56 | * @param string $editor_script_handle |
||
57 | */ |
||
58 | View Code Duplication | public function setEditorScriptHandle($editor_script_handle) |
|
65 | |||
66 | |||
67 | /** |
||
68 | * @return string |
||
69 | */ |
||
70 | public function getEditorStyleHandle() |
||
74 | |||
75 | |||
76 | /** |
||
77 | * @param string $editor_style_handle |
||
78 | */ |
||
79 | View Code Duplication | public function setEditorStyleHandle($editor_style_handle) |
|
86 | |||
87 | |||
88 | /** |
||
89 | * @return string |
||
90 | */ |
||
91 | public function getScriptHandle() |
||
95 | |||
96 | |||
97 | /** |
||
98 | * @param string $script_handle |
||
99 | */ |
||
100 | View Code Duplication | public function setScriptHandle($script_handle) |
|
107 | |||
108 | |||
109 | /** |
||
110 | * @return string |
||
111 | */ |
||
112 | public function getStyleHandle() |
||
116 | |||
117 | |||
118 | /** |
||
119 | * @param string $style_handle |
||
120 | */ |
||
121 | View Code Duplication | public function setStyleHandle($style_handle) |
|
128 | |||
129 | /** |
||
130 | * @since $VID:$ |
||
131 | * @throws InvalidDataTypeException |
||
132 | * @throws InvalidEntityException |
||
133 | * @throws DuplicateCollectionIdentifierException |
||
134 | */ |
||
135 | public function addAssets() |
||
142 | |||
143 | |||
144 | /** |
||
145 | * @param $handle |
||
146 | * @param array $dependencies |
||
147 | * @since $VID:$ |
||
148 | * @return JavascriptAsset |
||
149 | * @throws InvalidDataTypeException |
||
150 | * @throws InvalidEntityException |
||
151 | * @throws DuplicateCollectionIdentifierException |
||
152 | */ |
||
153 | View Code Duplication | public function addEditorScript($handle, array $dependencies = array()) |
|
168 | |||
169 | |||
170 | /** |
||
171 | * @param $handle |
||
172 | * @param array $dependencies |
||
173 | * @since $VID:$ |
||
174 | * @return StylesheetAsset |
||
175 | * @throws InvalidDataTypeException |
||
176 | * @throws InvalidEntityException |
||
177 | * @throws DuplicateCollectionIdentifierException |
||
178 | */ |
||
179 | View Code Duplication | public function addEditorStyle($handle, array $dependencies = array()) |
|
193 | |||
194 | |||
195 | /** |
||
196 | * @param $handle |
||
197 | * @param array $dependencies |
||
198 | * @since $VID:$ |
||
199 | * @return JavascriptAsset |
||
200 | * @throws InvalidDataTypeException |
||
201 | * @throws InvalidEntityException |
||
202 | * @throws DuplicateCollectionIdentifierException |
||
203 | */ |
||
204 | View Code Duplication | public function addScript($handle, array $dependencies = array()) |
|
219 | |||
220 | |||
221 | /** |
||
222 | * @param $handle |
||
223 | * @param array $dependencies |
||
224 | * @since $VID:$ |
||
225 | * @return StylesheetAsset |
||
226 | * @throws InvalidDataTypeException |
||
227 | * @throws InvalidEntityException |
||
228 | * @throws DuplicateCollectionIdentifierException |
||
229 | */ |
||
230 | View Code Duplication | public function addStyle($handle, array $dependencies = array()) |
|
244 | |||
245 | |||
246 | /** |
||
247 | * @param array $dependencies |
||
248 | * @return array |
||
249 | */ |
||
250 | protected function addDefaultBlockScriptDependencies(array $dependencies) |
||
261 | |||
262 | |||
263 | /** |
||
264 | * @param array $dependencies |
||
265 | * @return array |
||
266 | */ |
||
267 | protected function addDefaultBlockStyleDependencies(array $dependencies) |
||
274 | |||
275 | |||
276 | /** |
||
277 | * @return JavascriptAsset|null |
||
278 | */ |
||
279 | public function getEditorScript() |
||
283 | |||
284 | |||
285 | /** |
||
286 | * @return StylesheetAsset|null |
||
287 | */ |
||
288 | public function getEditorStyle() |
||
292 | |||
293 | |||
294 | /** |
||
295 | * @return JavascriptAsset|null |
||
296 | */ |
||
297 | public function getScript() |
||
301 | |||
302 | |||
303 | /** |
||
304 | * @return StylesheetAsset|null |
||
305 | */ |
||
306 | public function getStyle() |
||
310 | |||
311 | |||
312 | /** |
||
313 | * @return void |
||
314 | */ |
||
315 | public function enqueueAssets() |
||
329 | |||
330 | } |
||
331 |