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 |
||
| 8 | class Migrator |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Pingpong Module instance. |
||
| 12 | * |
||
| 13 | * @var \Nwidart\Modules\Module |
||
| 14 | */ |
||
| 15 | protected $module; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Laravel Application instance. |
||
| 19 | * |
||
| 20 | * @var \Illuminate\Foundation\Application. |
||
| 21 | */ |
||
| 22 | protected $laravel; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * The database connection to be used |
||
| 26 | * |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | protected $database = ''; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Create new instance. |
||
| 33 | * |
||
| 34 | * @param \Nwidart\Modules\Module $module |
||
| 35 | */ |
||
| 36 | 1 | public function __construct(Module $module) |
|
| 41 | |||
| 42 | /** |
||
| 43 | * Set the database connection to be used |
||
| 44 | * |
||
| 45 | * @param $database |
||
| 46 | * |
||
| 47 | * @return $this |
||
| 48 | */ |
||
| 49 | public function setDatabase($database) |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @return Module |
||
| 58 | */ |
||
| 59 | 1 | public function getModule() |
|
| 63 | |||
| 64 | /** |
||
| 65 | * Get migration path. |
||
| 66 | * |
||
| 67 | * @return string |
||
| 68 | */ |
||
| 69 | 1 | public function getPath() |
|
| 77 | |||
| 78 | /** |
||
| 79 | * Get migration files. |
||
| 80 | * |
||
| 81 | * @param boolean $reverse |
||
| 82 | * @return array |
||
| 83 | */ |
||
| 84 | public function getMigrations($reverse = false) |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Rollback migration. |
||
| 114 | * |
||
| 115 | * @return array |
||
| 116 | */ |
||
| 117 | View Code Duplication | public function rollback() |
|
| 139 | |||
| 140 | /** |
||
| 141 | * Reset migration. |
||
| 142 | * |
||
| 143 | * @return array |
||
| 144 | */ |
||
| 145 | View Code Duplication | public function reset() |
|
| 167 | |||
| 168 | /** |
||
| 169 | * Run down schema from the given migration name. |
||
| 170 | * |
||
| 171 | * @param string $migration |
||
| 172 | */ |
||
| 173 | public function down($migration) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Run up schema from the given migration name. |
||
| 180 | * |
||
| 181 | * @param string $migration |
||
| 182 | */ |
||
| 183 | public function up($migration) |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Resolve a migration instance from a file. |
||
| 190 | * |
||
| 191 | * @param string $file |
||
| 192 | * |
||
| 193 | * @return object |
||
| 194 | */ |
||
| 195 | public function resolve($file) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Require in all the migration files in a given path. |
||
| 206 | * |
||
| 207 | * @param array $files |
||
| 208 | */ |
||
| 209 | public function requireFiles(array $files) |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Get table instance. |
||
| 219 | * |
||
| 220 | * @return string |
||
| 221 | */ |
||
| 222 | public function table() |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Find migration data from database by given migration name. |
||
| 229 | * |
||
| 230 | * @param string $migration |
||
| 231 | * |
||
| 232 | * @return object |
||
| 233 | */ |
||
| 234 | public function find($migration) |
||
| 238 | |||
| 239 | /** |
||
| 240 | * Save new migration to database. |
||
| 241 | * |
||
| 242 | * @param string $migration |
||
| 243 | * |
||
| 244 | * @return mixed |
||
| 245 | */ |
||
| 246 | public function log($migration) |
||
| 253 | |||
| 254 | /** |
||
| 255 | * Get the next migration batch number. |
||
| 256 | * |
||
| 257 | * @return int |
||
| 258 | */ |
||
| 259 | public function getNextBatchNumber() |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Get the last migration batch number. |
||
| 266 | * |
||
| 267 | * @param array $migrations |
||
| 268 | * @return int |
||
| 269 | */ |
||
| 270 | public function getLastBatchNumber($migrations) |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Get the last migration batch. |
||
| 279 | * |
||
| 280 | * @param array $migrations |
||
| 281 | * |
||
| 282 | * @return Collection |
||
| 283 | */ |
||
| 284 | public function getLast($migrations) |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Get the ran migrations. |
||
| 299 | * |
||
| 300 | * @return Collection |
||
| 301 | */ |
||
| 302 | public function getRan() |
||
| 306 | } |
||
| 307 |
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..