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) |
|
| 124 | |||
| 125 | /** |
||
| 126 | 32 | * Sets the config. |
|
| 127 | * |
||
| 128 | 32 | * @param \Phinx\Config\ConfigInterface $config |
|
| 129 | 32 | * @return \Phinx\Console\Command\AbstractCommand |
|
| 130 | */ |
||
| 131 | public function setConfig(ConfigInterface $config) |
||
| 137 | 32 | ||
| 138 | /** |
||
| 139 | 32 | * Gets the config. |
|
| 140 | * |
||
| 141 | * @return \Phinx\Config\ConfigInterface |
||
| 142 | */ |
||
| 143 | public function getConfig() |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Sets the database adapter. |
||
| 150 | * |
||
| 151 | * @param \Phinx\Db\Adapter\AdapterInterface $adapter |
||
| 152 | * @return \Phinx\Console\Command\AbstractCommand |
||
| 153 | */ |
||
| 154 | public function setAdapter(AdapterInterface $adapter) |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Gets the database adapter. |
||
| 163 | * |
||
| 164 | * @return \Phinx\Db\Adapter\AdapterInterface |
||
| 165 | */ |
||
| 166 | public function getAdapter() |
||
| 170 | 32 | ||
| 171 | /** |
||
| 172 | 32 | * Sets the migration manager. |
|
| 173 | 32 | * |
|
| 174 | * @param \Phinx\Migration\Manager $manager |
||
| 175 | * @return \Phinx\Console\Command\AbstractCommand |
||
| 176 | */ |
||
| 177 | public function setManager(Manager $manager) |
||
| 183 | 32 | ||
| 184 | /** |
||
| 185 | * Gets the migration manager. |
||
| 186 | * |
||
| 187 | * @return \Phinx\Migration\Manager|null |
||
| 188 | */ |
||
| 189 | public function getManager() |
||
| 193 | |||
| 194 | 10 | /** |
|
| 195 | * Returns config file path |
||
| 196 | 10 | * |
|
| 197 | * @param \Symfony\Component\Console\Input\InputInterface $input |
||
| 198 | 10 | * @return string |
|
| 199 | 4 | */ |
|
| 200 | 4 | protected function locateConfigFile(InputInterface $input) |
|
| 233 | |||
| 234 | /** |
||
| 235 | * Parse the config file and load it into the config object |
||
| 236 | * |
||
| 237 | * @param \Symfony\Component\Console\Input\InputInterface $input |
||
| 238 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
| 239 | * @throws \InvalidArgumentException |
||
| 240 | * @return void |
||
| 241 | */ |
||
| 242 | protected function loadConfig(InputInterface $input, OutputInterface $output) |
||
| 284 | |||
| 285 | 32 | /** |
|
| 286 | * Load the migrations manager and inject the config |
||
| 287 | * |
||
| 288 | * @param \Symfony\Component\Console\Input\InputInterface $input |
||
| 289 | 32 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
|
| 290 | 32 | */ |
|
| 291 | 32 | protected function loadManager(InputInterface $input, OutputInterface $output) |
|
| 302 | 13 | ||
| 303 | /** |
||
| 304 | 13 | * Verify that the migration directory exists and is writable. |
|
| 305 | * |
||
| 306 | * @param string $path |
||
| 307 | * @throws \InvalidArgumentException |
||
| 308 | * @return void |
||
| 309 | */ |
||
| 310 | View Code Duplication | protected function verifyMigrationDirectory($path) |
|
| 326 | 2 | ||
| 327 | /** |
||
| 328 | 2 | * Verify that the seed directory exists and is writable. |
|
| 329 | * |
||
| 330 | * @param string $path |
||
| 331 | * @throws \InvalidArgumentException |
||
| 332 | * @return void |
||
| 333 | */ |
||
| 334 | View Code Duplication | protected function verifySeedDirectory($path) |
|
| 350 | 2 | ||
| 351 | /** |
||
| 352 | * Returns the migration template filename. |
||
| 353 | * |
||
| 354 | * @return string |
||
| 355 | */ |
||
| 356 | protected function getMigrationTemplateFilename() |
||
| 360 | 1 | ||
| 361 | /** |
||
| 362 | * Returns the seed template filename. |
||
| 363 | * |
||
| 364 | * @return string |
||
| 365 | */ |
||
| 366 | protected function getSeedTemplateFilename() |
||
| 370 | } |
||
| 371 |
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.