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 |
||
23 | abstract class BlockAssetManager extends AssetManager implements BlockAssetManagerInterface |
||
24 | { |
||
25 | |||
26 | /** |
||
27 | * @var string $editor_script_handle |
||
28 | */ |
||
29 | private $editor_script_handle; |
||
30 | |||
31 | /** |
||
32 | * @var string $editor_style_handle |
||
33 | */ |
||
34 | private $editor_style_handle; |
||
35 | |||
36 | /** |
||
37 | * @var string $script_handle |
||
38 | */ |
||
39 | private $script_handle; |
||
40 | |||
41 | /** |
||
42 | * @var string $style_handle |
||
43 | */ |
||
44 | private $style_handle; |
||
45 | |||
46 | |||
47 | /** |
||
48 | * @return string |
||
49 | */ |
||
50 | public function getEditorScriptHandle() |
||
54 | |||
55 | |||
56 | /** |
||
57 | * @param string $editor_script_handle |
||
58 | */ |
||
59 | View Code Duplication | public function setEditorScriptHandle($editor_script_handle) |
|
66 | |||
67 | |||
68 | /** |
||
69 | * @return string |
||
70 | */ |
||
71 | public function getEditorStyleHandle() |
||
75 | |||
76 | |||
77 | /** |
||
78 | * @param string $editor_style_handle |
||
79 | */ |
||
80 | View Code Duplication | public function setEditorStyleHandle($editor_style_handle) |
|
87 | |||
88 | |||
89 | /** |
||
90 | * @return string |
||
91 | */ |
||
92 | public function getScriptHandle() |
||
96 | |||
97 | |||
98 | /** |
||
99 | * @param string $script_handle |
||
100 | */ |
||
101 | View Code Duplication | public function setScriptHandle($script_handle) |
|
108 | |||
109 | |||
110 | /** |
||
111 | * @return string |
||
112 | */ |
||
113 | public function getStyleHandle() |
||
117 | |||
118 | |||
119 | /** |
||
120 | * @param string $style_handle |
||
121 | */ |
||
122 | View Code Duplication | public function setStyleHandle($style_handle) |
|
129 | |||
130 | /** |
||
131 | * @since $VID:$ |
||
132 | * @throws InvalidDataTypeException |
||
133 | * @throws InvalidEntityException |
||
134 | * @throws DuplicateCollectionIdentifierException |
||
135 | */ |
||
136 | public function addAssets() |
||
143 | |||
144 | |||
145 | /** |
||
146 | * @param $handle |
||
147 | * @param array $dependencies |
||
148 | * @since $VID:$ |
||
149 | * @return JavascriptAsset |
||
150 | * @throws InvalidDataTypeException |
||
151 | * @throws InvalidEntityException |
||
152 | * @throws DuplicateCollectionIdentifierException |
||
153 | */ |
||
154 | View Code Duplication | public function addEditorScript($handle, array $dependencies = array()) |
|
169 | |||
170 | |||
171 | /** |
||
172 | * @param $handle |
||
173 | * @param array $dependencies |
||
174 | * @since $VID:$ |
||
175 | * @return StylesheetAsset |
||
176 | * @throws InvalidDataTypeException |
||
177 | * @throws InvalidEntityException |
||
178 | * @throws DuplicateCollectionIdentifierException |
||
179 | */ |
||
180 | View Code Duplication | public function addEditorStyle($handle, array $dependencies = array()) |
|
194 | |||
195 | |||
196 | /** |
||
197 | * @param $handle |
||
198 | * @param array $dependencies |
||
199 | * @since $VID:$ |
||
200 | * @return JavascriptAsset |
||
201 | * @throws InvalidDataTypeException |
||
202 | * @throws InvalidEntityException |
||
203 | * @throws DuplicateCollectionIdentifierException |
||
204 | */ |
||
205 | View Code Duplication | public function addScript($handle, array $dependencies = array()) |
|
220 | |||
221 | |||
222 | /** |
||
223 | * @param $handle |
||
224 | * @param array $dependencies |
||
225 | * @since $VID:$ |
||
226 | * @return StylesheetAsset |
||
227 | * @throws InvalidDataTypeException |
||
228 | * @throws InvalidEntityException |
||
229 | * @throws DuplicateCollectionIdentifierException |
||
230 | */ |
||
231 | View Code Duplication | public function addStyle($handle, array $dependencies = array()) |
|
245 | |||
246 | |||
247 | /** |
||
248 | * @param array $dependencies |
||
249 | * @return array |
||
250 | */ |
||
251 | protected function addDefaultBlockScriptDependencies(array $dependencies) |
||
262 | |||
263 | |||
264 | /** |
||
265 | * @return JavascriptAsset|null |
||
266 | */ |
||
267 | public function getEditorScript() |
||
271 | |||
272 | |||
273 | /** |
||
274 | * @return StylesheetAsset|null |
||
275 | */ |
||
276 | public function getEditorStyle() |
||
280 | |||
281 | |||
282 | /** |
||
283 | * @return JavascriptAsset|null |
||
284 | */ |
||
285 | public function getScript() |
||
289 | |||
290 | |||
291 | /** |
||
292 | * @return StylesheetAsset|null |
||
293 | */ |
||
294 | public function getStyle() |
||
298 | |||
299 | |||
300 | /** |
||
301 | * @return void |
||
302 | */ |
||
303 | public function enqueueAssets() |
||
317 | |||
318 | } |
||
319 |