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 | * @param mixed $identifier |
||
| 115 | * @param string $type |
||
| 116 | * @return bool |
||
| 117 | * @since $VID:$ |
||
| 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 | * @param mixed $identifier |
||
| 140 | * @return bool |
||
| 141 | * @since $VID:$ |
||
| 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 | * @param mixed $identifier |
||
| 156 | * @return bool |
||
| 157 | * @since $VID:$ |
||
| 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 | * @param mixed $identifier |
||
| 171 | * @param string $type |
||
| 172 | * @return JavascriptAsset|StylesheetAsset |
||
| 173 | * @since $VID:$ |
||
| 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 | * @param mixed $identifier |
||
| 198 | * @return StylesheetAsset |
||
| 199 | * @since $VID:$ |
||
| 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 | * @param mixed $identifier |
||
| 214 | * @return JavascriptAsset |
||
| 215 | * @since $VID:$ |
||
| 216 | */ |
||
| 217 | public function getJavascriptAsset($identifier) |
||
| 221 | } |
||
| 222 |