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 |
||
6 | View Code Duplication | class AddDescriptionFieldForPermission extends AbstractMigration |
|
7 | { |
||
8 | /** |
||
9 | * Change Method. |
||
10 | * |
||
11 | * Write your reversible migrations using this method. |
||
12 | * |
||
13 | * More information on writing migrations is available here: |
||
14 | * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class |
||
15 | * |
||
16 | * The following commands can be used in this method and Phinx will |
||
17 | * automatically reverse them when rolling back: |
||
18 | * |
||
19 | * createTable |
||
20 | * renameTable |
||
21 | * addColumn |
||
22 | * renameColumn |
||
23 | * addIndex |
||
24 | * addForeignKey |
||
25 | * |
||
26 | * Remember to call "create()" or "update()" and NOT "save()" when working |
||
27 | * with the Table class. |
||
28 | */ |
||
29 | public function change() |
||
37 | } |
||
38 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.