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 |
||
| 22 | abstract class BlockAssetManager extends AssetManager implements BlockAssetManagerInterface |
||
| 23 | { |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var string $editor_script_handle |
||
| 27 | */ |
||
| 28 | private $editor_script_handle; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var string $editor_style_handle |
||
| 32 | */ |
||
| 33 | private $editor_style_handle; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var string $script_handle |
||
| 37 | */ |
||
| 38 | private $script_handle; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var string $style_handle |
||
| 42 | */ |
||
| 43 | private $style_handle; |
||
| 44 | |||
| 45 | |||
| 46 | /** |
||
| 47 | * @return string |
||
| 48 | */ |
||
| 49 | public function getEditorScriptHandle() |
||
| 53 | |||
| 54 | |||
| 55 | /** |
||
| 56 | * @param string $editor_script_handle |
||
| 57 | */ |
||
| 58 | View Code Duplication | public function setEditorScriptHandle($editor_script_handle) |
|
| 65 | |||
| 66 | |||
| 67 | /** |
||
| 68 | * @return string |
||
| 69 | */ |
||
| 70 | public function getEditorStyleHandle() |
||
| 74 | |||
| 75 | |||
| 76 | /** |
||
| 77 | * @param string $editor_style_handle |
||
| 78 | */ |
||
| 79 | View Code Duplication | public function setEditorStyleHandle($editor_style_handle) |
|
| 86 | |||
| 87 | |||
| 88 | /** |
||
| 89 | * @return string |
||
| 90 | */ |
||
| 91 | public function getScriptHandle() |
||
| 95 | |||
| 96 | |||
| 97 | /** |
||
| 98 | * @param string $script_handle |
||
| 99 | */ |
||
| 100 | View Code Duplication | public function setScriptHandle($script_handle) |
|
| 107 | |||
| 108 | |||
| 109 | /** |
||
| 110 | * @return string |
||
| 111 | */ |
||
| 112 | public function getStyleHandle() |
||
| 116 | |||
| 117 | |||
| 118 | /** |
||
| 119 | * @param string $style_handle |
||
| 120 | */ |
||
| 121 | View Code Duplication | public function setStyleHandle($style_handle) |
|
| 128 | |||
| 129 | /** |
||
| 130 | * @since 4.9.71.p |
||
| 131 | * @throws InvalidDataTypeException |
||
| 132 | * @throws InvalidEntityException |
||
| 133 | * @throws DuplicateCollectionIdentifierException |
||
| 134 | */ |
||
| 135 | public function addAssets() |
||
| 142 | |||
| 143 | |||
| 144 | /** |
||
| 145 | * @param $handle |
||
| 146 | * @param array $dependencies |
||
| 147 | * @since 4.9.71.p |
||
| 148 | * @return JavascriptAsset |
||
| 149 | * @throws InvalidDataTypeException |
||
| 150 | * @throws InvalidEntityException |
||
| 151 | * @throws DuplicateCollectionIdentifierException |
||
| 152 | */ |
||
| 153 | View Code Duplication | public function addEditorScript($handle, array $dependencies = array()) |
|
| 160 | |||
| 161 | |||
| 162 | /** |
||
| 163 | * @param $handle |
||
| 164 | * @param array $dependencies |
||
| 165 | * @since 4.9.71.p |
||
| 166 | * @return StylesheetAsset |
||
| 167 | * @throws InvalidDataTypeException |
||
| 168 | * @throws InvalidEntityException |
||
| 169 | * @throws DuplicateCollectionIdentifierException |
||
| 170 | */ |
||
| 171 | View Code Duplication | public function addEditorStyle($handle, array $dependencies = array()) |
|
| 178 | |||
| 179 | |||
| 180 | /** |
||
| 181 | * @param $handle |
||
| 182 | * @param array $dependencies |
||
| 183 | * @since 4.9.71.p |
||
| 184 | * @return JavascriptAsset |
||
| 185 | * @throws InvalidDataTypeException |
||
| 186 | * @throws InvalidEntityException |
||
| 187 | * @throws DuplicateCollectionIdentifierException |
||
| 188 | */ |
||
| 189 | View Code Duplication | public function addScript($handle, array $dependencies = array()) |
|
| 196 | |||
| 197 | |||
| 198 | /** |
||
| 199 | * @param $handle |
||
| 200 | * @param array $dependencies |
||
| 201 | * @since 4.9.71.p |
||
| 202 | * @return StylesheetAsset |
||
| 203 | * @throws InvalidDataTypeException |
||
| 204 | * @throws InvalidEntityException |
||
| 205 | * @throws DuplicateCollectionIdentifierException |
||
| 206 | */ |
||
| 207 | View Code Duplication | public function addStyle($handle, array $dependencies = array()) |
|
| 214 | |||
| 215 | |||
| 216 | /** |
||
| 217 | * @return JavascriptAsset|null |
||
| 218 | */ |
||
| 219 | public function getEditorScript() |
||
| 223 | |||
| 224 | |||
| 225 | /** |
||
| 226 | * @return StylesheetAsset|null |
||
| 227 | */ |
||
| 228 | public function getEditorStyle() |
||
| 232 | |||
| 233 | |||
| 234 | /** |
||
| 235 | * @return JavascriptAsset|null |
||
| 236 | */ |
||
| 237 | public function getScript() |
||
| 241 | |||
| 242 | |||
| 243 | /** |
||
| 244 | * @return StylesheetAsset|null |
||
| 245 | */ |
||
| 246 | public function getStyle() |
||
| 250 | |||
| 251 | |||
| 252 | /** |
||
| 253 | * @return void |
||
| 254 | */ |
||
| 255 | public function enqueueAssets() |
||
| 269 | |||
| 270 | } |
||
| 271 |