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 |
||
| 37 | final class Shopware_Plugins_Backend_SwagConnect_Bootstrap extends Shopware_Components_Plugin_Bootstrap |
||
|
|
|||
| 38 | { |
||
| 39 | /** |
||
| 40 | * @var SubscriberRegistration |
||
| 41 | */ |
||
| 42 | private $subscriberRegistration; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var ConnectFactory |
||
| 46 | */ |
||
| 47 | private $connectFactory; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Returns the current version of the plugin. |
||
| 51 | * |
||
| 52 | * @return string|void |
||
| 53 | * @throws Exception |
||
| 54 | */ |
||
| 55 | public function getVersion() |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Returns a nice name for plugin manager list |
||
| 68 | * |
||
| 69 | * @return string |
||
| 70 | */ |
||
| 71 | public function getLabel() |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @return array |
||
| 78 | */ |
||
| 79 | public function getInfo() |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Install plugin method |
||
| 91 | * |
||
| 92 | * @throws \RuntimeException |
||
| 93 | * @return bool |
||
| 94 | */ |
||
| 95 | public function install() |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @param $version string |
||
| 104 | * @return array |
||
| 105 | */ |
||
| 106 | public function update($version) |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Uninstall plugin method |
||
| 125 | * |
||
| 126 | * @return bool |
||
| 127 | */ |
||
| 128 | public function uninstall() |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Performs the default setup of the system. |
||
| 137 | * |
||
| 138 | * This can be used by the update as well as by the install method |
||
| 139 | * |
||
| 140 | * @param bool $fullSetup |
||
| 141 | * @throws RuntimeException |
||
| 142 | */ |
||
| 143 | View Code Duplication | public function doSetup($fullSetup = true) |
|
| 160 | |||
| 161 | /** |
||
| 162 | * Performs the update of the system |
||
| 163 | * |
||
| 164 | * @param $version |
||
| 165 | * @return bool |
||
| 166 | */ |
||
| 167 | public function doUpdate($version) |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Uninstall the plugin |
||
| 182 | */ |
||
| 183 | View Code Duplication | public function doUninstall() |
|
| 200 | |||
| 201 | /** |
||
| 202 | * Will dynamically register all needed events |
||
| 203 | * |
||
| 204 | * @param Enlight_Event_EventArgs $args |
||
| 205 | */ |
||
| 206 | public function onStartDispatch(Enlight_Event_EventArgs $args) |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @return ArrayCollection |
||
| 214 | */ |
||
| 215 | public function onConsoleAddCommand() |
||
| 224 | |||
| 225 | public function onInitResourceSDK() |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Register additional namespaces for the libraries |
||
| 234 | */ |
||
| 235 | public function registerMyLibrary() |
||
| 252 | |||
| 253 | /** |
||
| 254 | * Lazy getter for the connectFactory |
||
| 255 | * |
||
| 256 | * @return ConnectFactory |
||
| 257 | */ |
||
| 258 | public function getConnectFactory() |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @return Shopware\Connect\SDK |
||
| 271 | */ |
||
| 272 | public function getSDK() |
||
| 276 | |||
| 277 | /** |
||
| 278 | * @return \ShopwarePlugins\Connect\Components\Helper |
||
| 279 | */ |
||
| 280 | public function getHelper() |
||
| 284 | |||
| 285 | public function getBasketHelper() |
||
| 289 | |||
| 290 | /** |
||
| 291 | * @return \ShopwarePlugins\Connect\Components\Config |
||
| 292 | */ |
||
| 293 | public function getConfigComponents() |
||
| 297 | |||
| 298 | public function getMarketplaceGateway() |
||
| 302 | |||
| 303 | public function getMarketplaceApplier() |
||
| 307 | |||
| 308 | /** |
||
| 309 | * @return bool |
||
| 310 | */ |
||
| 311 | private function isInstalled() |
||
| 329 | |||
| 330 | private function registerSubscribers() |
||
| 347 | } |
||
| 348 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.