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 |
||
20 | class AssetCollection extends Collection |
||
21 | { |
||
22 | |||
23 | |||
24 | /** |
||
25 | * AssetCollection constructor |
||
26 | * |
||
27 | * @throws InvalidInterfaceException |
||
28 | */ |
||
29 | public function __construct() |
||
33 | |||
34 | |||
35 | /** |
||
36 | * @return StylesheetAsset[] |
||
37 | * @since 4.9.62.p |
||
38 | */ |
||
39 | public function getStylesheetAssets() |
||
43 | |||
44 | |||
45 | /** |
||
46 | * @return JavascriptAsset[] |
||
47 | * @since 4.9.62.p |
||
48 | */ |
||
49 | public function getJavascriptAssets() |
||
53 | |||
54 | |||
55 | /** |
||
56 | * @return ManifestFile[] |
||
57 | * @since 4.9.62.p |
||
58 | */ |
||
59 | public function getManifestFiles() |
||
63 | |||
64 | |||
65 | /** |
||
66 | * @param $type |
||
67 | * @return JavascriptAsset[]|StylesheetAsset[]|ManifestFile[] |
||
68 | * @since 4.9.62.p |
||
69 | */ |
||
70 | View Code Duplication | protected function getAssetsOfType($type) |
|
85 | |||
86 | |||
87 | /** |
||
88 | * @return JavascriptAsset[] |
||
89 | * @since 4.9.62.p |
||
90 | */ |
||
91 | View Code Duplication | public function getJavascriptAssetsWithData() |
|
106 | |||
107 | |||
108 | /** |
||
109 | * has |
||
110 | * returns TRUE or FALSE |
||
111 | * depending on whether the object is within the Collection |
||
112 | * based on the supplied $identifier and type |
||
113 | * |
||
114 | * @access public |
||
115 | * @param mixed $identifier |
||
116 | * @param string $type |
||
117 | * @return bool |
||
118 | */ |
||
119 | View Code Duplication | public function hasAssetOfType($identifier, $type = Asset::TYPE_JS) |
|
131 | |||
132 | |||
133 | /** |
||
134 | * has |
||
135 | * returns TRUE or FALSE |
||
136 | * depending on whether the Stylesheet Asset is within the Collection |
||
137 | * based on the supplied $identifier |
||
138 | * |
||
139 | * @access public |
||
140 | * @param mixed $identifier |
||
141 | * @return bool |
||
142 | */ |
||
143 | public function hasStylesheetAsset($identifier) |
||
147 | |||
148 | |||
149 | /** |
||
150 | * has |
||
151 | * returns TRUE or FALSE |
||
152 | * depending on whether the Javascript Asset is within the Collection |
||
153 | * based on the supplied $identifier |
||
154 | * |
||
155 | * @access public |
||
156 | * @param mixed $identifier |
||
157 | * @return bool |
||
158 | */ |
||
159 | public function hasJavascriptAsset($identifier) |
||
163 | |||
164 | /** |
||
165 | * has |
||
166 | * returns TRUE or FALSE |
||
167 | * depending on whether the object is within the Collection |
||
168 | * based on the supplied $identifier and type |
||
169 | * |
||
170 | * @access public |
||
171 | * @param mixed $identifier |
||
172 | * @param string $type |
||
173 | * @return JavascriptAsset|StylesheetAsset |
||
174 | */ |
||
175 | View Code Duplication | public function getAssetOfType($identifier, $type = Asset::TYPE_JS) |
|
189 | |||
190 | |||
191 | /** |
||
192 | * has |
||
193 | * returns TRUE or FALSE |
||
194 | * depending on whether the Stylesheet Asset is within the Collection |
||
195 | * based on the supplied $identifier |
||
196 | * |
||
197 | * @access public |
||
198 | * @param mixed $identifier |
||
199 | * @return StylesheetAsset |
||
200 | */ |
||
201 | public function getStylesheetAsset($identifier) |
||
205 | |||
206 | |||
207 | /** |
||
208 | * has |
||
209 | * returns TRUE or FALSE |
||
210 | * depending on whether the Javascript Asset is within the Collection |
||
211 | * based on the supplied $identifier |
||
212 | * |
||
213 | * @access public |
||
214 | * @param mixed $identifier |
||
215 | * @return JavascriptAsset |
||
216 | */ |
||
217 | public function getJavascriptAsset($identifier) |
||
221 | } |
||
222 |