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 |
||
| 27 | class Config |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * @var array config data |
||
| 31 | */ |
||
| 32 | private $config = array(); |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var ConfigurationLoader |
||
| 36 | */ |
||
| 37 | private $loader; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var array |
||
| 41 | */ |
||
| 42 | private $initConfig; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var boolean |
||
| 46 | */ |
||
| 47 | private $isPharMode; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var OutputInterface |
||
| 51 | */ |
||
| 52 | private $output; |
||
| 53 | |||
| 54 | |||
| 55 | /** |
||
| 56 | * Config constructor. |
||
| 57 | * @param array $initConfig |
||
| 58 | * @param bool $isPharMode |
||
| 59 | * @param OutputInterface $output [optional] |
||
|
1 ignored issue
–
show
|
|||
| 60 | */ |
||
| 61 | public function __construct(array $initConfig = array(), $isPharMode = false, OutputInterface $output = null) |
||
| 67 | |||
| 68 | /** |
||
| 69 | * alias magerun command in input from config |
||
| 70 | * |
||
| 71 | * @param InputInterface $input |
||
| 72 | * @return ArgvInput|InputInterface |
||
| 73 | */ |
||
| 74 | public function checkConfigCommandAlias(InputInterface $input) |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @param Command $command |
||
| 104 | */ |
||
| 105 | public function registerConfigCommandAlias(Command $command) |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @return bool |
||
| 128 | */ |
||
| 129 | private function hasConfigCommandAliases() |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @param Application $application |
||
| 136 | */ |
||
| 137 | public function registerCustomCommands(Application $application) |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Adds autoloader prefixes from user's config |
||
| 166 | * |
||
| 167 | * @param ClassLoader $autoloader |
||
| 168 | */ |
||
| 169 | public function registerCustomAutoloaders(ClassLoader $autoloader) |
||
| 199 | |||
| 200 | /** |
||
| 201 | * @param array $config |
||
| 202 | */ |
||
| 203 | public function setConfig(array $config) |
||
| 207 | |||
| 208 | /** |
||
| 209 | * @return array |
||
| 210 | */ |
||
| 211 | public function getConfig() |
||
| 215 | |||
| 216 | /** |
||
| 217 | * @param ConfigurationLoader $configurationLoader |
||
| 218 | * |
||
| 219 | * @return $this |
||
| 220 | */ |
||
| 221 | public function setConfigurationLoader(ConfigurationLoader $configurationLoader) { |
||
| 224 | |||
| 225 | /** |
||
| 226 | * @return ConfigurationLoader |
||
| 227 | */ |
||
| 228 | public function getLoader() |
||
| 237 | |||
| 238 | public function load() |
||
| 242 | |||
| 243 | /** |
||
| 244 | * @param array $initConfig |
||
| 245 | * @param bool $isPharMode |
||
| 246 | * @param OutputInterface $output |
||
| 247 | * |
||
| 248 | * @return ConfigurationLoader |
||
| 249 | */ |
||
| 250 | public function createLoader(array $initConfig, $isPharMode, OutputInterface $output) |
||
| 258 | } |
||
| 259 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.