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 |
||
| 16 | class RenameExtension implements DatabasePlatformAwareInterface, NameGeneratorAwareInterface |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @var AbstractPlatform |
||
| 20 | */ |
||
| 21 | protected $platform; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var DbIdentifierNameGenerator |
||
| 25 | */ |
||
| 26 | protected $nameGenerator; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * {@inheritdoc} |
||
| 30 | */ |
||
| 31 | public function setDatabasePlatform(AbstractPlatform $platform) |
||
| 35 | |||
| 36 | /** |
||
| 37 | * {@inheritdoc} |
||
| 38 | */ |
||
| 39 | public function setNameGenerator(DbIdentifierNameGenerator $nameGenerator) |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Renames a table |
||
| 46 | * |
||
| 47 | * @param Schema $schema |
||
| 48 | * @param QueryBag $queries |
||
| 49 | * @param string $oldTableName |
||
| 50 | * @param string $newTableName |
||
| 51 | */ |
||
| 52 | public function renameTable(Schema $schema, QueryBag $queries, $oldTableName, $newTableName) |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Renames a column |
||
| 67 | * |
||
| 68 | * @param Schema $schema |
||
| 69 | * @param QueryBag $queries |
||
| 70 | * @param Table $table |
||
| 71 | * @param string $oldColumnName |
||
| 72 | * @param string $newColumnName |
||
| 73 | */ |
||
| 74 | public function renameColumn(Schema $schema, QueryBag $queries, Table $table, $oldColumnName, $newColumnName) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Create an index without check of table and columns existence. |
||
| 90 | * This method can be helpful when you need to create an index for renamed table or column |
||
| 91 | * |
||
| 92 | * @param Schema $schema |
||
| 93 | * @param QueryBag $queries |
||
| 94 | * @param string $tableName |
||
| 95 | * @param string[] $columnNames |
||
| 96 | * @param string|null $indexName |
||
| 97 | */ |
||
| 98 | View Code Duplication | public function addIndex( |
|
| 118 | |||
| 119 | /** |
||
| 120 | * Create an unique index without check of table and columns existence. |
||
| 121 | * This method can be helpful when you need to create an index for renamed table or column |
||
| 122 | * |
||
| 123 | * @param Schema $schema |
||
| 124 | * @param QueryBag $queries |
||
| 125 | * @param string $tableName |
||
| 126 | * @param string[] $columnNames |
||
| 127 | * @param string|null $indexName |
||
| 128 | */ |
||
| 129 | View Code Duplication | public function addUniqueIndex( |
|
| 149 | |||
| 150 | /** |
||
| 151 | * Create a foreign key constraint without check of table and columns existence. |
||
| 152 | * This method can be helpful when you need to create a constraint for renamed table or column |
||
| 153 | * |
||
| 154 | * @param Schema $schema |
||
| 155 | * @param QueryBag $queries |
||
| 156 | * @param string $tableName |
||
| 157 | * @param string $foreignTable |
||
| 158 | * @param string[] $localColumnNames |
||
| 159 | * @param string[] $foreignColumnNames |
||
| 160 | * @param array $options |
||
| 161 | * @param string|null $constraintName |
||
| 162 | */ |
||
| 163 | public function addForeignKeyConstraint( |
||
| 195 | } |
||
| 196 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.