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 | * @return JavascriptAsset |
||
105 | * @throws DuplicateCollectionIdentifierException |
||
106 | * @throws InvalidDataTypeException |
||
107 | * @throws InvalidEntityException |
||
108 | * @since 4.9.62.p |
||
109 | */ |
||
110 | View Code Duplication | public function addJavascript( |
|
126 | |||
127 | |||
128 | /** |
||
129 | * Used to register a javascript asset where everything is dynamically derived from the given handle. |
||
130 | * |
||
131 | * @param string $handle |
||
132 | * @param string|array $extra_dependencies |
||
133 | * @return JavascriptAsset |
||
134 | * @throws DuplicateCollectionIdentifierException |
||
135 | * @throws InvalidDataTypeException |
||
136 | * @throws InvalidEntityException |
||
137 | */ |
||
138 | View Code Duplication | public function addJs($handle, $extra_dependencies = []) |
|
153 | |||
154 | |||
155 | /** |
||
156 | * @param string $handle |
||
157 | * @param array $dependencies |
||
158 | * @param bool $load_in_footer |
||
159 | * @return JavascriptAsset |
||
160 | * @throws DuplicateCollectionIdentifierException |
||
161 | * @throws InvalidDataTypeException |
||
162 | * @throws InvalidEntityException |
||
163 | * @throws DomainException |
||
164 | * @since 4.9.71.p |
||
165 | */ |
||
166 | public function addVendorJavascript( |
||
180 | |||
181 | |||
182 | |||
183 | /** |
||
184 | * @param string $handle |
||
185 | * @param string $source |
||
186 | * @param array $dependencies |
||
187 | * @param string $media |
||
188 | * @return StylesheetAsset |
||
189 | * @throws DuplicateCollectionIdentifierException |
||
190 | * @throws InvalidDataTypeException |
||
191 | * @throws InvalidEntityException |
||
192 | * @since 4.9.62.p |
||
193 | */ |
||
194 | View Code Duplication | public function addStylesheet( |
|
210 | |||
211 | |||
212 | /** |
||
213 | * Used to register a css asset where everything is dynamically derived from the given handle. |
||
214 | * |
||
215 | * @param string $handle |
||
216 | * @param string|array $extra_dependencies |
||
217 | * @return StylesheetAsset |
||
218 | * @throws DuplicateCollectionIdentifierException |
||
219 | * @throws InvalidDataTypeException |
||
220 | * @throws InvalidEntityException |
||
221 | */ |
||
222 | View Code Duplication | public function addCss($handle, $extra_dependencies = []) |
|
237 | |||
238 | |||
239 | /** |
||
240 | * @param string $handle |
||
241 | * @return bool |
||
242 | * @since 4.9.62.p |
||
243 | */ |
||
244 | public function enqueueAsset($handle) |
||
255 | } |
||
256 |