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 Plugins extends Base |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @return PluginsService |
||
| 24 | */ |
||
| 25 | 6 | protected function getPluginService() |
|
| 29 | |||
| 30 | /** |
||
| 31 | * @return UpdatesService |
||
| 32 | */ |
||
| 33 | 5 | protected function getUpdatesService() |
|
| 37 | |||
| 38 | /** |
||
| 39 | * Installs plugin by handle. |
||
| 40 | * |
||
| 41 | * @param string $handle |
||
| 42 | */ |
||
| 43 | 3 | protected function installPluginByHandle($handle) |
|
| 53 | |||
| 54 | /** |
||
| 55 | * Uninstalls plugin by handle. |
||
| 56 | * |
||
| 57 | * @param $handle |
||
| 58 | */ |
||
| 59 | 1 | protected function uninstallPluginByHandle($handle) |
|
| 63 | |||
| 64 | /** |
||
| 65 | * Returns plugin by handle. |
||
| 66 | * |
||
| 67 | * @param string $handle |
||
| 68 | * |
||
| 69 | * @return BasePlugin|null |
||
| 70 | */ |
||
| 71 | 5 | protected function getPlugin($handle) |
|
| 80 | |||
| 81 | /** |
||
| 82 | * Toggles plugin based on enabled flag. |
||
| 83 | * |
||
| 84 | * @param string $handle |
||
| 85 | * @param bool $isEnabled |
||
| 86 | */ |
||
| 87 | 3 | protected function togglePluginByHandle($handle, $isEnabled) |
|
| 95 | |||
| 96 | /** |
||
| 97 | * Run plugin migrations automatically. |
||
| 98 | * |
||
| 99 | * @param string $handle |
||
| 100 | * |
||
| 101 | * @throws Exception |
||
| 102 | */ |
||
| 103 | protected function runMigrations($handle) |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @param BasePlugin $plugin |
||
| 113 | * |
||
| 114 | * @return array |
||
| 115 | */ |
||
| 116 | 1 | private function getPluginDefinition(BasePlugin $plugin) |
|
| 124 | |||
| 125 | /** |
||
| 126 | * @param array $pluginDefinitions |
||
| 127 | * @param bool $force |
||
| 128 | * |
||
| 129 | * @return Result |
||
| 130 | */ |
||
| 131 | 5 | public function import(array $pluginDefinitions, $force = false) |
|
| 169 | |||
| 170 | /** |
||
| 171 | * @param array $data |
||
| 172 | * |
||
| 173 | * @return array |
||
| 174 | */ |
||
| 175 | 1 | View Code Duplication | public function export(array $data = []) |
| 190 | } |
||
| 191 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.