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 namespace Xethron\MigrationsGenerator; |
||
| 20 | class MigrateGenerateCommand extends GeneratorCommand { |
||
| 21 | |||
| 22 | /** |
||
| 23 | * The console command name. |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | protected $name = 'migrate:generate'; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * The console command description. |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | protected $description = 'Generate a migration from an existing table structure.'; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var \Way\Generators\Filesystem\Filesystem |
||
| 36 | */ |
||
| 37 | protected $file; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var \Way\Generators\Compilers\TemplateCompiler |
||
| 41 | */ |
||
| 42 | protected $compiler; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var \Illuminate\Database\Migrations\MigrationRepositoryInterface $repository |
||
| 46 | */ |
||
| 47 | protected $repository; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var \Illuminate\Config\Repository $config |
||
| 51 | */ |
||
| 52 | protected $config; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var \Xethron\MigrationsGenerator\Generators\SchemaGenerator |
||
| 56 | */ |
||
| 57 | protected $schemaGenerator; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Array of Fields to create in a new Migration |
||
| 61 | * Namely: Columns, Indexes and Foreign Keys |
||
| 62 | * @var array |
||
| 63 | */ |
||
| 64 | protected $fields = array(); |
||
| 65 | |||
| 66 | /** |
||
| 67 | * List of Migrations that has been done |
||
| 68 | * @var array |
||
| 69 | */ |
||
| 70 | protected $migrations = array(); |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @var bool |
||
| 74 | */ |
||
| 75 | protected $log = false; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @var int |
||
| 79 | */ |
||
| 80 | protected $batch; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Filename date prefix (Y_m_d_His) |
||
| 84 | * @var string |
||
| 85 | */ |
||
| 86 | protected $datePrefix; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @var string |
||
| 90 | */ |
||
| 91 | protected $migrationName; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @var string |
||
| 95 | */ |
||
| 96 | protected $method; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @var string |
||
| 100 | */ |
||
| 101 | protected $table; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @var string|null |
||
| 105 | */ |
||
| 106 | protected $connection = null; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @param \Way\Generators\Generator $generator |
||
| 110 | * @param \Way\Generators\Filesystem\Filesystem $file |
||
| 111 | * @param \Way\Generators\Compilers\TemplateCompiler $compiler |
||
| 112 | * @param \Illuminate\Database\Migrations\MigrationRepositoryInterface $repository |
||
| 113 | * @param \Illuminate\Config\Repository $config |
||
| 114 | */ |
||
| 115 | public function __construct( |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Execute the console command. Added for Laravel 5.5 |
||
| 133 | * |
||
| 134 | * @return void |
||
| 135 | */ |
||
| 136 | public function handle() |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Execute the console command. |
||
| 143 | * |
||
| 144 | * @return void |
||
| 145 | */ |
||
| 146 | public function fire() |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Ask for user input: Yes/No |
||
| 194 | * @param string $question Question to ask |
||
| 195 | * @return boolean Answer from user |
||
| 196 | */ |
||
| 197 | protected function askYn( $question ) { |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Ask user for a Numeric Value, or blank for default |
||
| 207 | * @param string $question Question to ask |
||
| 208 | * @param int|float $default Default Value (optional) |
||
| 209 | * @return int|float Answer |
||
| 210 | */ |
||
| 211 | protected function askNumeric( $question, $default = null ) { |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Generate tables and index migrations. |
||
| 232 | * |
||
| 233 | * @param array $tables List of tables to create migrations for |
||
| 234 | * @return void |
||
| 235 | */ |
||
| 236 | View Code Duplication | protected function generateTablesAndIndices( array $tables ) |
|
| 248 | |||
| 249 | /** |
||
| 250 | * Generate foreign key migrations. |
||
| 251 | * |
||
| 252 | * @param array $tables List of tables to create migrations for |
||
| 253 | * @return void |
||
| 254 | */ |
||
| 255 | View Code Duplication | protected function generateForeignKeys( array $tables ) |
|
| 267 | |||
| 268 | /** |
||
| 269 | * Generate Migration for the current table. |
||
| 270 | * |
||
| 271 | * @return void |
||
| 272 | */ |
||
| 273 | protected function generate() |
||
| 284 | |||
| 285 | /** |
||
| 286 | * The path where the file will be created |
||
| 287 | * |
||
| 288 | * @return string |
||
| 289 | */ |
||
| 290 | protected function getFileGenerationPath() |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Get the date prefix for the migration. |
||
| 301 | * |
||
| 302 | * @return string |
||
| 303 | */ |
||
| 304 | protected function getDatePrefix() |
||
| 308 | |||
| 309 | /** |
||
| 310 | * Fetch the template data |
||
| 311 | * |
||
| 312 | * @return array |
||
| 313 | */ |
||
| 314 | protected function getTemplateData() |
||
| 332 | |||
| 333 | /** |
||
| 334 | * Get path to template for generator |
||
| 335 | * |
||
| 336 | * @return string |
||
| 337 | */ |
||
| 338 | protected function getTemplatePath() |
||
| 342 | |||
| 343 | /** |
||
| 344 | * Get the console command arguments. |
||
| 345 | * |
||
| 346 | * @return array |
||
| 347 | */ |
||
| 348 | protected function getArguments() |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Get the console command options. |
||
| 357 | * |
||
| 358 | * @return array |
||
| 359 | */ |
||
| 360 | protected function getOptions() |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Remove all the tables to exclude from the array of tables |
||
| 375 | * |
||
| 376 | * @param array $tables |
||
| 377 | * |
||
| 378 | * @return array |
||
| 379 | */ |
||
| 380 | protected function removeExcludedTables( array $tables ) |
||
| 387 | |||
| 388 | /** |
||
| 389 | * Get a list of tables to exclude |
||
| 390 | * |
||
| 391 | * @return array |
||
| 392 | */ |
||
| 393 | protected function getExcludedTables() |
||
| 403 | |||
| 404 | } |
||
| 405 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..