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 AssetManager implements AssetManagerInterface |
||
24 | { |
||
25 | |||
26 | /** |
||
27 | * @var AssetCollection $assets |
||
28 | */ |
||
29 | protected $assets; |
||
30 | |||
31 | /** |
||
32 | * @var DomainInterface |
||
33 | */ |
||
34 | protected $domain; |
||
35 | |||
36 | /** |
||
37 | * @var Registry $registry |
||
38 | */ |
||
39 | protected $registry; |
||
40 | |||
41 | |||
42 | /** |
||
43 | * AssetRegister constructor. |
||
44 | * |
||
45 | * @param DomainInterface $domain |
||
46 | * @param AssetCollection $assets |
||
47 | * @param Registry $registry |
||
48 | */ |
||
49 | public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry) |
||
59 | |||
60 | |||
61 | /** |
||
62 | * @since 4.9.71.p |
||
63 | * @return string |
||
64 | */ |
||
65 | public function assetNamespace() |
||
69 | |||
70 | |||
71 | /** |
||
72 | * @return void |
||
73 | * @throws DuplicateCollectionIdentifierException |
||
74 | * @throws InvalidDataTypeException |
||
75 | * @throws InvalidEntityException |
||
76 | * @since 4.9.62.p |
||
77 | */ |
||
78 | public function addManifestFile() |
||
87 | |||
88 | |||
89 | /** |
||
90 | * @return ManifestFile[] |
||
91 | * @since 4.9.62.p |
||
92 | */ |
||
93 | public function getManifestFile() |
||
97 | |||
98 | |||
99 | /** |
||
100 | * @param string $handle |
||
101 | * @param string $source |
||
102 | * @param array $dependencies |
||
103 | * @param bool $load_in_footer |
||
104 | * @param string $version |
||
105 | * @return JavascriptAsset |
||
106 | * @throws DuplicateCollectionIdentifierException |
||
107 | * @throws InvalidDataTypeException |
||
108 | * @throws InvalidEntityException |
||
109 | * @throws DomainException |
||
110 | * @since 4.9.62.p |
||
111 | */ |
||
112 | View Code Duplication | public function addJavascript( |
|
130 | |||
131 | |||
132 | /** |
||
133 | * Used to register a javascript asset where everything is dynamically derived from the given handle. |
||
134 | * |
||
135 | * @param string $handle |
||
136 | * @param string|array $extra_dependencies |
||
137 | * @return JavascriptAsset |
||
138 | * @throws DuplicateCollectionIdentifierException |
||
139 | * @throws InvalidDataTypeException |
||
140 | * @throws InvalidEntityException |
||
141 | * @throws DomainException |
||
142 | */ |
||
143 | View Code Duplication | public function addJs($handle, $extra_dependencies = []) |
|
158 | |||
159 | |||
160 | /** |
||
161 | * @param string $handle |
||
162 | * @param array $dependencies |
||
163 | * @param bool $load_in_footer |
||
164 | * @param string $version |
||
165 | * @return JavascriptAsset |
||
166 | * @throws DomainException |
||
167 | * @throws DuplicateCollectionIdentifierException |
||
168 | * @throws InvalidDataTypeException |
||
169 | * @throws InvalidEntityException |
||
170 | * @since 4.9.71.p |
||
171 | */ |
||
172 | public function addVendorJavascript( |
||
188 | |||
189 | |||
190 | /** |
||
191 | * @param string $handle |
||
192 | * @param string $source |
||
193 | * @param array $dependencies |
||
194 | * @param string $media |
||
195 | * @param string $version |
||
196 | * @return StylesheetAsset |
||
197 | * @throws DomainException |
||
198 | * @throws DuplicateCollectionIdentifierException |
||
199 | * @throws InvalidDataTypeException |
||
200 | * @throws InvalidEntityException |
||
201 | * @since 4.9.62.p |
||
202 | */ |
||
203 | View Code Duplication | public function addStylesheet( |
|
221 | |||
222 | |||
223 | /** |
||
224 | * Used to register a css asset where everything is dynamically derived from the given handle. |
||
225 | * |
||
226 | * @param string $handle |
||
227 | * @param string|array $extra_dependencies |
||
228 | * @return StylesheetAsset |
||
229 | * @throws DuplicateCollectionIdentifierException |
||
230 | * @throws InvalidDataTypeException |
||
231 | * @throws InvalidEntityException |
||
232 | * @throws DomainException |
||
233 | */ |
||
234 | View Code Duplication | public function addCss($handle, $extra_dependencies = []) |
|
249 | |||
250 | |||
251 | /** |
||
252 | * @param string $handle |
||
253 | * @return bool |
||
254 | * @since 4.9.62.p |
||
255 | */ |
||
256 | public function enqueueAsset($handle) |
||
267 | |||
268 | |||
269 | /** |
||
270 | * @param string $asset_type |
||
271 | * @param string $handle |
||
272 | * @param array $extra_dependencies |
||
273 | * @return array |
||
274 | * @since $VID:$ |
||
275 | */ |
||
276 | private function getAssetDetails($asset_type, $handle, $extra_dependencies = []) |
||
306 | } |
||
307 |