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 |
||
| 10 | class Migrator |
||
| 11 | { |
||
| 12 | use Paths; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Yarak config. |
||
| 16 | * |
||
| 17 | * @var Config |
||
| 18 | */ |
||
| 19 | protected $config; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Database connection resolver. |
||
| 23 | * |
||
| 24 | * @var ConnectionResolver |
||
| 25 | */ |
||
| 26 | protected $resolver; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Repository for logging migration activity. |
||
| 30 | * |
||
| 31 | * @var MigrationRepository |
||
| 32 | */ |
||
| 33 | protected $repository; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * The active database connection. |
||
| 37 | * |
||
| 38 | * @var Phalcon\Db\Adapter\Pdo |
||
| 39 | */ |
||
| 40 | protected $connection = null; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Log of info/error messages. |
||
| 44 | * |
||
| 45 | * @var array |
||
| 46 | */ |
||
| 47 | protected $log = []; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Construct. |
||
| 51 | * |
||
| 52 | * @param Config $config |
||
| 53 | * @param ConnectionResolver $resolver |
||
| 54 | * @param MigrationRepositoryInterface $repository |
||
| 55 | */ |
||
| 56 | public function __construct( |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Run migrations. |
||
| 68 | * |
||
| 69 | * @return array |
||
| 70 | */ |
||
| 71 | public function run() |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Get all migration filenames that have not been run. |
||
| 82 | * |
||
| 83 | * @return array |
||
| 84 | */ |
||
| 85 | protected function getPendingMigrations() |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Get array of migration file names from directory listed in config. |
||
| 95 | * |
||
| 96 | * @return array |
||
| 97 | */ |
||
| 98 | protected function getMigrationFiles() |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Run pending migrations. |
||
| 115 | * |
||
| 116 | * @param array $migrations |
||
| 117 | * |
||
| 118 | * @return array |
||
| 119 | */ |
||
| 120 | protected function runPending(array $migrations) |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Run the migration. |
||
| 143 | * |
||
| 144 | * @param string $migration |
||
| 145 | * @param int $batch |
||
| 146 | */ |
||
| 147 | View Code Duplication | protected function runUp($migration, $batch) |
|
| 161 | |||
| 162 | /** |
||
| 163 | * Resolve the migration class from the file name. |
||
| 164 | * |
||
| 165 | * @param string $migration |
||
| 166 | * |
||
| 167 | * @return Yarak\Migrations\Migration |
||
| 168 | */ |
||
| 169 | public function resolveMigrationClass($migration) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Rollback migrations. |
||
| 180 | * |
||
| 181 | * @param int $steps |
||
| 182 | * |
||
| 183 | * @return array |
||
| 184 | */ |
||
| 185 | public function rollback($steps = 1) |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Rollback given migrations. |
||
| 196 | * |
||
| 197 | * @param array $migrations |
||
| 198 | * |
||
| 199 | * @return array |
||
| 200 | */ |
||
| 201 | protected function runRollback(array $migrations) |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Rollback the migration. |
||
| 222 | * |
||
| 223 | * @param string $migration |
||
| 224 | */ |
||
| 225 | View Code Duplication | protected function runDown($migration) |
|
| 239 | |||
| 240 | /** |
||
| 241 | * Reset the database by rolling back all migrations. |
||
| 242 | * |
||
| 243 | * @return array |
||
| 244 | */ |
||
| 245 | public function reset() |
||
| 253 | |||
| 254 | /** |
||
| 255 | * Reset the database and run all migrations. |
||
| 256 | * |
||
| 257 | * @return array |
||
| 258 | */ |
||
| 259 | public function refresh() |
||
| 271 | |||
| 272 | /** |
||
| 273 | * Perform setup procedures for migrations. |
||
| 274 | */ |
||
| 275 | protected function setUp() |
||
| 285 | |||
| 286 | /** |
||
| 287 | * Set connection to database on object. |
||
| 288 | * |
||
| 289 | * @return Pdo |
||
| 290 | */ |
||
| 291 | public function setConnection() |
||
| 301 | |||
| 302 | /** |
||
| 303 | * Return the connection. |
||
| 304 | * |
||
| 305 | * @return Phalcon\Db\Adapter\Pdo |
||
| 306 | */ |
||
| 307 | public function getConnection() |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Create the migrations table if it doesn't exist. |
||
| 314 | */ |
||
| 315 | public function createMigrationsRepository() |
||
| 323 | |||
| 324 | /** |
||
| 325 | * Log a message. |
||
| 326 | * |
||
| 327 | * @param string $message |
||
| 328 | */ |
||
| 329 | protected function log($message) |
||
| 333 | |||
| 334 | /** |
||
| 335 | * Return the object log. |
||
| 336 | * |
||
| 337 | * @return array |
||
| 338 | */ |
||
| 339 | public function getLog() |
||
| 343 | } |
||
| 344 |
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..