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 |
||
21 | abstract class BlockAssetManager extends AssetManager implements BlockAssetManagerInterface |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | * @var string $editor_script_handle |
||
26 | */ |
||
27 | private $editor_script_handle; |
||
28 | |||
29 | /** |
||
30 | * @var string $editor_style_handle |
||
31 | */ |
||
32 | private $editor_style_handle; |
||
33 | |||
34 | /** |
||
35 | * @var string $script_handle |
||
36 | */ |
||
37 | private $script_handle; |
||
38 | |||
39 | /** |
||
40 | * @var string $style_handle |
||
41 | */ |
||
42 | private $style_handle; |
||
43 | |||
44 | |||
45 | /** |
||
46 | * @return string |
||
47 | */ |
||
48 | public function getEditorScriptHandle() |
||
52 | |||
53 | |||
54 | /** |
||
55 | * @param string $editor_script_handle |
||
56 | */ |
||
57 | public function setEditorScriptHandle($editor_script_handle) |
||
61 | |||
62 | |||
63 | /** |
||
64 | * @return string |
||
65 | */ |
||
66 | public function getEditorStyleHandle() |
||
70 | |||
71 | |||
72 | /** |
||
73 | * @param string $editor_style_handle |
||
74 | */ |
||
75 | public function setEditorStyleHandle($editor_style_handle) |
||
79 | |||
80 | |||
81 | /** |
||
82 | * @return string |
||
83 | */ |
||
84 | public function getScriptHandle() |
||
88 | |||
89 | |||
90 | /** |
||
91 | * @param string $script_handle |
||
92 | */ |
||
93 | public function setScriptHandle($script_handle) |
||
97 | |||
98 | |||
99 | /** |
||
100 | * @return string |
||
101 | */ |
||
102 | public function getStyleHandle() |
||
106 | |||
107 | |||
108 | /** |
||
109 | * @param string $style_handle |
||
110 | */ |
||
111 | public function setStyleHandle($style_handle) |
||
115 | |||
116 | /** |
||
117 | * @since $VID:$ |
||
118 | * @throws InvalidDataTypeException |
||
119 | * @throws InvalidEntityException |
||
120 | * @throws DuplicateCollectionIdentifierException |
||
121 | */ |
||
122 | public function addAssets() |
||
129 | |||
130 | |||
131 | /** |
||
132 | * @param $handle |
||
133 | * @param array $dependencies |
||
134 | * @since $VID:$ |
||
135 | * @return JavascriptAsset |
||
136 | * @throws InvalidDataTypeException |
||
137 | * @throws InvalidEntityException |
||
138 | * @throws DuplicateCollectionIdentifierException |
||
139 | */ |
||
140 | View Code Duplication | public function addEditorScript($handle, array $dependencies = array()) |
|
154 | |||
155 | |||
156 | /** |
||
157 | * @param $handle |
||
158 | * @param array $dependencies |
||
159 | * @since $VID:$ |
||
160 | * @return StylesheetAsset |
||
161 | * @throws InvalidDataTypeException |
||
162 | * @throws InvalidEntityException |
||
163 | * @throws DuplicateCollectionIdentifierException |
||
164 | */ |
||
165 | View Code Duplication | public function addEditorStyle($handle, array $dependencies = array()) |
|
179 | |||
180 | |||
181 | /** |
||
182 | * @param $handle |
||
183 | * @param array $dependencies |
||
184 | * @since $VID:$ |
||
185 | * @return JavascriptAsset |
||
186 | * @throws InvalidDataTypeException |
||
187 | * @throws InvalidEntityException |
||
188 | * @throws DuplicateCollectionIdentifierException |
||
189 | */ |
||
190 | View Code Duplication | public function addScript($handle, array $dependencies = array()) |
|
204 | |||
205 | |||
206 | /** |
||
207 | * @param $handle |
||
208 | * @param array $dependencies |
||
209 | * @since $VID:$ |
||
210 | * @return StylesheetAsset |
||
211 | * @throws InvalidDataTypeException |
||
212 | * @throws InvalidEntityException |
||
213 | * @throws DuplicateCollectionIdentifierException |
||
214 | */ |
||
215 | View Code Duplication | public function addStyle($handle, array $dependencies = array()) |
|
229 | |||
230 | |||
231 | /** |
||
232 | * @param array $dependencies |
||
233 | * @return array |
||
234 | */ |
||
235 | protected function addDefaultBlockScriptDependencies(array $dependencies) |
||
246 | |||
247 | |||
248 | /** |
||
249 | * @param string $handle |
||
250 | * @since $VID:$ |
||
251 | * @return mixed|null |
||
252 | */ |
||
253 | public function getAsset($handle) |
||
260 | |||
261 | |||
262 | /** |
||
263 | * @return JavascriptAsset|null |
||
264 | */ |
||
265 | public function getEditorScript() |
||
269 | |||
270 | |||
271 | /** |
||
272 | * @return StylesheetAsset|null |
||
273 | */ |
||
274 | public function getEditorStyle() |
||
278 | |||
279 | |||
280 | /** |
||
281 | * @return JavascriptAsset|null |
||
282 | */ |
||
283 | public function getScript() |
||
287 | |||
288 | |||
289 | /** |
||
290 | * @return StylesheetAsset|null |
||
291 | */ |
||
292 | public function getStyle() |
||
296 | |||
297 | |||
298 | /** |
||
299 | * @return void |
||
300 | */ |
||
301 | public function enqueueAssets() |
||
315 | |||
316 | } |
||
317 |