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 |
||
| 47 | abstract class AbstractCommand extends Command |
||
| 48 | { |
||
| 49 | /** |
||
| 50 | * The location of the default migration template. |
||
| 51 | */ |
||
| 52 | const DEFAULT_MIGRATION_TEMPLATE = '/../../Migration/Migration.template.php.dist'; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * The location of the default seed template. |
||
| 56 | */ |
||
| 57 | const DEFAULT_SEED_TEMPLATE = '/../../Seed/Seed.template.php.dist'; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var \Phinx\Config\ConfigInterface |
||
| 61 | */ |
||
| 62 | protected $config; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var \Phinx\Db\Adapter\AdapterInterface |
||
| 66 | */ |
||
| 67 | protected $adapter; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var \Phinx\Migration\Manager |
||
| 71 | */ |
||
| 72 | protected $manager; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * {@inheritdoc} |
||
| 76 | */ |
||
| 77 | 54 | protected function configure() |
|
| 82 | |||
| 83 | /** |
||
| 84 | * Bootstrap Phinx. |
||
| 85 | * |
||
| 86 | * @param \Symfony\Component\Console\Input\InputInterface $input |
||
| 87 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
| 88 | * @return void |
||
| 89 | */ |
||
| 90 | 32 | public function bootstrap(InputInterface $input, OutputInterface $output) |
|
| 119 | |||
| 120 | /** |
||
| 121 | * Sets the config. |
||
| 122 | * |
||
| 123 | * @param \Phinx\Config\ConfigInterface $config |
||
| 124 | * @return \Phinx\Console\Command\AbstractCommand |
||
| 125 | */ |
||
| 126 | 32 | public function setConfig(ConfigInterface $config) |
|
| 132 | |||
| 133 | /** |
||
| 134 | * Gets the config. |
||
| 135 | * |
||
| 136 | * @return \Phinx\Config\ConfigInterface |
||
| 137 | 32 | */ |
|
| 138 | public function getConfig() |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Sets the database adapter. |
||
| 145 | * |
||
| 146 | * @param \Phinx\Db\Adapter\AdapterInterface $adapter |
||
| 147 | * @return \Phinx\Console\Command\AbstractCommand |
||
| 148 | */ |
||
| 149 | public function setAdapter(AdapterInterface $adapter) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Gets the database adapter. |
||
| 158 | * |
||
| 159 | * @return \Phinx\Db\Adapter\AdapterInterface |
||
| 160 | */ |
||
| 161 | public function getAdapter() |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Sets the migration manager. |
||
| 168 | * |
||
| 169 | * @param \Phinx\Migration\Manager $manager |
||
| 170 | 32 | * @return \Phinx\Console\Command\AbstractCommand |
|
| 171 | */ |
||
| 172 | 32 | public function setManager(Manager $manager) |
|
| 178 | |||
| 179 | /** |
||
| 180 | * Gets the migration manager. |
||
| 181 | 32 | * |
|
| 182 | * @return \Phinx\Migration\Manager|null |
||
| 183 | 32 | */ |
|
| 184 | public function getManager() |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Returns config file path |
||
| 191 | * |
||
| 192 | 10 | * @param \Symfony\Component\Console\Input\InputInterface $input |
|
| 193 | * @return string |
||
| 194 | 10 | */ |
|
| 195 | protected function locateConfigFile(InputInterface $input) |
||
| 228 | |||
| 229 | /** |
||
| 230 | * Parse the config file and load it into the config object |
||
| 231 | * |
||
| 232 | * @param \Symfony\Component\Console\Input\InputInterface $input |
||
| 233 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
| 234 | * @throws \InvalidArgumentException |
||
| 235 | * @return void |
||
| 236 | */ |
||
| 237 | protected function loadConfig(InputInterface $input, OutputInterface $output) |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Load the migrations manager and inject the config |
||
| 282 | * |
||
| 283 | 32 | * @param \Symfony\Component\Console\Input\InputInterface $input |
|
| 284 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
| 285 | 32 | */ |
|
| 286 | protected function loadManager(InputInterface $input, OutputInterface $output) |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Verify that the migration directory exists and is writable. |
||
| 300 | * |
||
| 301 | * @param string $path |
||
| 302 | 13 | * @throws \InvalidArgumentException |
|
| 303 | * @return void |
||
| 304 | 13 | */ |
|
| 305 | View Code Duplication | protected function verifyMigrationDirectory($path) |
|
| 321 | |||
| 322 | /** |
||
| 323 | * Verify that the seed directory exists and is writable. |
||
| 324 | * |
||
| 325 | * @param string $path |
||
| 326 | 2 | * @throws \InvalidArgumentException |
|
| 327 | * @return void |
||
| 328 | 2 | */ |
|
| 329 | View Code Duplication | protected function verifySeedDirectory($path) |
|
| 345 | |||
| 346 | /** |
||
| 347 | * Returns the migration template filename. |
||
| 348 | 2 | * |
|
| 349 | * @return string |
||
| 350 | 2 | */ |
|
| 351 | protected function getMigrationTemplateFilename() |
||
| 355 | |||
| 356 | /** |
||
| 357 | * Returns the seed template filename. |
||
| 358 | 1 | * |
|
| 359 | * @return string |
||
| 360 | 1 | */ |
|
| 361 | protected function getSeedTemplateFilename() |
||
| 365 | } |
||
| 366 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.