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 |
||
| 24 | final class Shopware_Plugins_Backend_SwagConnect_Bootstrap extends Shopware_Components_Plugin_Bootstrap |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * @var SubscriberRegistration |
||
| 28 | */ |
||
| 29 | private $subscriberRegistration; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var ConnectFactory |
||
| 33 | */ |
||
| 34 | private $connectFactory; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Returns the current version of the plugin. |
||
| 38 | * |
||
| 39 | * @throws Exception |
||
| 40 | * @return string|void |
||
| 41 | */ |
||
| 42 | public function getVersion() |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Returns a nice name for plugin manager list |
||
| 54 | * |
||
| 55 | * @return string |
||
| 56 | */ |
||
| 57 | public function getLabel() |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @return array |
||
| 64 | */ |
||
| 65 | public function getInfo() |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Install plugin method |
||
| 77 | * |
||
| 78 | * @throws \RuntimeException |
||
| 79 | * @return array |
||
| 80 | */ |
||
| 81 | public function install() |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @param $version string |
||
| 90 | * @return array |
||
| 91 | */ |
||
| 92 | public function update($version) |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Uninstall plugin method |
||
| 111 | * |
||
| 112 | * @return array |
||
| 113 | */ |
||
| 114 | public function uninstall() |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Performs the default setup of the system. |
||
| 123 | * |
||
| 124 | * This can be used by the update as well as by the install method |
||
| 125 | * |
||
| 126 | * @param bool $fullSetup |
||
| 127 | * @throws RuntimeException |
||
| 128 | */ |
||
| 129 | View Code Duplication | public function doSetup($fullSetup = true) |
|
| 146 | |||
| 147 | /** |
||
| 148 | * Performs the update of the system |
||
| 149 | * |
||
| 150 | * @param $version |
||
| 151 | * @return bool |
||
| 152 | */ |
||
| 153 | public function doUpdate($version) |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Uninstall the plugin |
||
| 170 | */ |
||
| 171 | View Code Duplication | public function doUninstall() |
|
| 189 | |||
| 190 | /** |
||
| 191 | * Will dynamically register all needed events |
||
| 192 | * |
||
| 193 | * @param Enlight_Event_EventArgs $args |
||
| 194 | */ |
||
| 195 | public function onStartDispatch(Enlight_Event_EventArgs $args) |
||
| 201 | |||
| 202 | public function registerTemplateDir() |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @return ArrayCollection |
||
| 209 | */ |
||
| 210 | public function onConsoleAddCommand() |
||
| 220 | |||
| 221 | public function onInitResourceSDK() |
||
| 227 | |||
| 228 | /** |
||
| 229 | * Register additional namespaces for the libraries |
||
| 230 | */ |
||
| 231 | public function registerMyLibrary() |
||
| 240 | |||
| 241 | /** |
||
| 242 | * Lazy getter for the connectFactory |
||
| 243 | * |
||
| 244 | * @return ConnectFactory |
||
| 245 | */ |
||
| 246 | public function getConnectFactory() |
||
| 256 | |||
| 257 | /** |
||
| 258 | * @return Shopware\Connect\SDK |
||
| 259 | */ |
||
| 260 | public function getSDK() |
||
| 264 | |||
| 265 | /** |
||
| 266 | * @return \ShopwarePlugins\Connect\Components\Helper |
||
| 267 | */ |
||
| 268 | public function getHelper() |
||
| 272 | |||
| 273 | /** |
||
| 274 | * @return BasketHelper |
||
| 275 | */ |
||
| 276 | public function getBasketHelper() |
||
| 280 | |||
| 281 | /** |
||
| 282 | * @return \ShopwarePlugins\Connect\Components\Config |
||
| 283 | */ |
||
| 284 | public function getConfigComponents() |
||
| 288 | |||
| 289 | /** |
||
| 290 | * @return bool |
||
| 291 | */ |
||
| 292 | private function isInstalled() |
||
| 310 | |||
| 311 | private function registerSubscribers() |
||
| 329 | } |
||
| 330 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.