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 |
||
| 18 | class PluginManager |
||
| 19 | { |
||
| 20 | /** @var PluginDescription[] List of all the plugins adescriptions. */ |
||
| 21 | protected $plugins = []; |
||
| 22 | |||
| 23 | /** @var PluginDescription[] Current List of enabled plugins */ |
||
| 24 | protected $enabledPlugins = []; |
||
| 25 | |||
| 26 | /** @var PluginDescriptionFactory */ |
||
| 27 | protected $pluginDescriptionFactory; |
||
| 28 | |||
| 29 | /** @var ContainerInterface */ |
||
| 30 | protected $container; |
||
| 31 | |||
| 32 | /** @var DataProviderManager */ |
||
| 33 | protected $dataProviderManager; |
||
| 34 | |||
| 35 | /** @var GameDataStorage */ |
||
| 36 | protected $gameDataStorage; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * PluginManager constructor. |
||
| 40 | * |
||
| 41 | * @param ContainerInterface $container |
||
| 42 | * @param DataProviderManager $dataProviderManager |
||
| 43 | */ |
||
| 44 | 40 | public function __construct( |
|
| 56 | |||
| 57 | /** |
||
| 58 | * Initialize plugins. |
||
| 59 | */ |
||
| 60 | public function init() |
||
| 64 | |||
| 65 | public function reset() |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Enable all possible plugins. |
||
| 76 | * |
||
| 77 | * @param string $title |
||
| 78 | * @param string $mode |
||
| 79 | * @param string $script |
||
| 80 | */ |
||
| 81 | protected function enableDisablePlugins($title, $mode, $script) |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Check if a plugin is compatible or not. |
||
| 114 | * |
||
| 115 | * @param PluginDescription $plugin |
||
| 116 | * @param $enabledPlugins |
||
| 117 | * @param $title |
||
| 118 | * @param $mode |
||
| 119 | * @param $script |
||
| 120 | * |
||
| 121 | * @return bool |
||
| 122 | */ |
||
| 123 | protected function isPluginCompatible(PluginDescription $plugin, $enabledPlugins, $title, $mode, $script) { |
||
| 155 | |||
| 156 | |||
| 157 | /** |
||
| 158 | * Enable a plugin for a certain game mode. |
||
| 159 | * |
||
| 160 | * @param PluginDescription $plugin |
||
| 161 | * @param $title |
||
| 162 | * @param $mode |
||
| 163 | * @param $script |
||
| 164 | */ |
||
| 165 | protected function enablePlugin(PluginDescription $plugin, $title, $mode, $script) { |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Disable a plugin. |
||
| 182 | * |
||
| 183 | * @param PluginDescription $plugin |
||
| 184 | * |
||
| 185 | */ |
||
| 186 | protected function disablePlugin(PluginDescription $plugin) { |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Check if a plugin is enabled or not. |
||
| 205 | * |
||
| 206 | * @param $pluginId |
||
| 207 | * |
||
| 208 | * @return bool |
||
| 209 | */ |
||
| 210 | public function isPluginEnabled($pluginId) { |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Register a plugin. |
||
| 216 | * |
||
| 217 | * @param string $id The service id of the plugin to register. |
||
| 218 | * @param string[] $dataProviders The data providers it needs to work. |
||
| 219 | * @param string[] $parents The parent plugins. |
||
| 220 | */ |
||
| 221 | 40 | public function registerPlugin($id, $dataProviders, $parents, $dataProviderName = null) { |
|
| 230 | } |
||
| 231 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: