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 |
||
| 7 | class Migrator |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Pingpong Module instance. |
||
| 11 | * |
||
| 12 | * @var \Nwidart\Modules\Module |
||
| 13 | */ |
||
| 14 | protected $module; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Laravel Application instance. |
||
| 18 | * |
||
| 19 | * @var \Illuminate\Foundation\Application. |
||
| 20 | */ |
||
| 21 | protected $laravel; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Create new instance. |
||
| 25 | * |
||
| 26 | * @param \Nwidart\Modules\Module $module |
||
| 27 | */ |
||
| 28 | 1 | public function __construct(Module $module) |
|
| 33 | |||
| 34 | /** |
||
| 35 | * @return Module |
||
| 36 | */ |
||
| 37 | 1 | public function getModule() |
|
| 41 | |||
| 42 | /** |
||
| 43 | * Get migration path. |
||
| 44 | * |
||
| 45 | * @return string |
||
| 46 | */ |
||
| 47 | 1 | public function getPath() |
|
| 55 | |||
| 56 | /** |
||
| 57 | * Get migration files. |
||
| 58 | * |
||
| 59 | * @param boolean $reverse |
||
| 60 | * @return array |
||
| 61 | */ |
||
| 62 | public function getMigrations($reverse = false) |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Rollback migration. |
||
| 92 | * |
||
| 93 | * @return array |
||
| 94 | */ |
||
| 95 | View Code Duplication | public function rollback() |
|
| 117 | |||
| 118 | /** |
||
| 119 | * Reset migration. |
||
| 120 | * |
||
| 121 | * @return array |
||
| 122 | */ |
||
| 123 | View Code Duplication | public function reset() |
|
| 145 | |||
| 146 | /** |
||
| 147 | * Run down schema from the given migration name. |
||
| 148 | * |
||
| 149 | * @param string $migration |
||
| 150 | */ |
||
| 151 | public function down($migration) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Run up schema from the given migration name. |
||
| 158 | * |
||
| 159 | * @param string $migration |
||
| 160 | */ |
||
| 161 | public function up($migration) |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Resolve a migration instance from a file. |
||
| 168 | * |
||
| 169 | * @param string $file |
||
| 170 | * |
||
| 171 | * @return object |
||
| 172 | */ |
||
| 173 | public function resolve($file) |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Require in all the migration files in a given path. |
||
| 184 | * |
||
| 185 | * @param array $files |
||
| 186 | */ |
||
| 187 | public function requireFiles(array $files) |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Get table instance. |
||
| 197 | * |
||
| 198 | * @return string |
||
| 199 | */ |
||
| 200 | public function table() |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Find migration data from database by given migration name. |
||
| 207 | * |
||
| 208 | * @param string $migration |
||
| 209 | * |
||
| 210 | * @return object |
||
| 211 | */ |
||
| 212 | public function find($migration) |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Save new migration to database. |
||
| 219 | * |
||
| 220 | * @param string $migration |
||
| 221 | * |
||
| 222 | * @return mixed |
||
| 223 | */ |
||
| 224 | public function log($migration) |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Get the next migration batch number. |
||
| 234 | * |
||
| 235 | * @return int |
||
| 236 | */ |
||
| 237 | public function getNextBatchNumber() |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Get the last migration batch number. |
||
| 244 | * |
||
| 245 | * @param array $migrations |
||
| 246 | * @return int |
||
| 247 | */ |
||
| 248 | public function getLastBatchNumber($migrations) |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Get the last migration batch. |
||
| 257 | * |
||
| 258 | * @param array $migrations |
||
| 259 | * |
||
| 260 | * @return array |
||
| 261 | */ |
||
| 262 | public function getLast($migrations) |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Get the ran migrations. |
||
| 277 | * |
||
| 278 | * @return array |
||
| 279 | */ |
||
| 280 | public function getRan() |
||
| 284 | } |
||
| 285 |
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..