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 |
||
| 21 | class Migrator extends Component implements SingletonInterface |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * @var MigrationsConfig |
||
| 25 | */ |
||
| 26 | private $config = null; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @invisible |
||
| 30 | * @var DatabaseManager |
||
| 31 | */ |
||
| 32 | private $dbal = null; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @invisible |
||
| 36 | * @var RepositoryInterface |
||
| 37 | */ |
||
| 38 | protected $repository = null; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param MigrationsConfig $config |
||
| 42 | * @param DatabaseManager $dbal |
||
| 43 | * @param RepositoryInterface $repository |
||
| 44 | */ |
||
| 45 | public function __construct( |
||
| 54 | |||
| 55 | /** |
||
| 56 | * {@inheritdoc} |
||
| 57 | */ |
||
| 58 | public function isConfigured(): bool |
||
| 62 | |||
| 63 | /** |
||
| 64 | * {@inheritdoc} |
||
| 65 | */ |
||
| 66 | public function configure() |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @return RepositoryInterface |
||
| 88 | */ |
||
| 89 | public function getRepository(): RepositoryInterface |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Get every available migration with valid meta information. |
||
| 96 | * |
||
| 97 | * @return MigrationInterface[] |
||
| 98 | */ |
||
| 99 | public function getMigrations(): array |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Execute one migration and return it's instance. |
||
| 112 | * |
||
| 113 | * @param CapsuleInterface $capsule Default capsule to be used if none given. |
||
| 114 | * |
||
| 115 | * @return MigrationInterface|null |
||
| 116 | */ |
||
| 117 | View Code Duplication | public function run(CapsuleInterface $capsule = null) |
|
| 148 | |||
| 149 | /** |
||
| 150 | * Rollback last migration and return it's instance. |
||
| 151 | * |
||
| 152 | * @param CapsuleInterface $capsule Default capsule to be used if none given. |
||
| 153 | * |
||
| 154 | * @return MigrationInterface|null |
||
| 155 | */ |
||
| 156 | View Code Duplication | public function rollback(CapsuleInterface $capsule = null) |
|
| 186 | |||
| 187 | /** |
||
| 188 | * Migration table, all migration information will be stored in it. |
||
| 189 | * |
||
| 190 | * @return Table |
||
| 191 | */ |
||
| 192 | protected function stateTable(): Table |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Clarify migration state with valid status and execution time |
||
| 199 | * |
||
| 200 | * @param State $meta |
||
| 201 | * |
||
| 202 | * @return State |
||
| 203 | */ |
||
| 204 | protected function resolveStatus(State $meta) |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Run given code under transaction open for every driver. |
||
| 226 | * |
||
| 227 | * @param \Closure $closure |
||
| 228 | * |
||
| 229 | * @throws \Throwable |
||
| 230 | */ |
||
| 231 | protected function execute(\Closure $closure) |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Begin transaction for every available driver (we don't know what database migration related |
||
| 246 | * to). |
||
| 247 | */ |
||
| 248 | protected function beginTransactions() |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Rollback transaction for every available driver. |
||
| 257 | */ |
||
| 258 | protected function rollbackTransactions() |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Commit transaction for every available driver. |
||
| 267 | */ |
||
| 268 | protected function commitTransactions() |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Get all available drivers. |
||
| 277 | * |
||
| 278 | * @return Driver[] |
||
| 279 | */ |
||
| 280 | protected function getDrivers() |
||
| 292 | } |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.