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 namespace Anomaly\Streams\Platform\Assignment; |
||
8 | class AssignmentSchema |
||
9 | { |
||
10 | |||
11 | /** |
||
12 | * The schema builder object. |
||
13 | * |
||
14 | * @var Builder |
||
15 | */ |
||
16 | protected $schema; |
||
17 | |||
18 | /** |
||
19 | * Create a new AssignmentSchema instance. |
||
20 | */ |
||
21 | public function __construct() |
||
25 | |||
26 | /** |
||
27 | * Add a column. |
||
28 | * |
||
29 | * @param $table |
||
30 | * @param FieldType $type |
||
31 | * @param AssignmentInterface $assignment |
||
32 | */ |
||
33 | View Code Duplication | public function addColumn($table, FieldType $type, AssignmentInterface $assignment) |
|
44 | |||
45 | /** |
||
46 | * Update a column. |
||
47 | * |
||
48 | * @param $table |
||
49 | * @param FieldType $type |
||
50 | * @param AssignmentInterface $assignment |
||
51 | */ |
||
52 | View Code Duplication | public function updateColumn($table, FieldType $type, AssignmentInterface $assignment) |
|
63 | |||
64 | /** |
||
65 | * Rename a column. |
||
66 | * |
||
67 | * @param $table |
||
68 | * @param FieldType $type |
||
69 | * @param AssignmentInterface $assignment |
||
70 | */ |
||
71 | public function renameColumn($table, FieldType $type, AssignmentInterface $assignment) |
||
87 | |||
88 | /** |
||
89 | * Change a column. |
||
90 | * |
||
91 | * @param $table |
||
92 | * @param FieldType $type |
||
93 | * @param AssignmentInterface $assignment |
||
94 | */ |
||
95 | public function changeColumn($table, FieldType $type, AssignmentInterface $assignment) |
||
115 | |||
116 | /** |
||
117 | * Drop a column. |
||
118 | * |
||
119 | * @param $table |
||
120 | * @param FieldType $type |
||
121 | */ |
||
122 | View Code Duplication | public function dropColumn($table, FieldType $type) |
|
137 | |||
138 | /** |
||
139 | * Backup a column's data. |
||
140 | * |
||
141 | * @param $table |
||
142 | * @param FieldType $type |
||
143 | */ |
||
144 | View Code Duplication | public function backupColumn($table, FieldType $type) |
|
159 | |||
160 | /** |
||
161 | * Restore a column's data. |
||
162 | * |
||
163 | * @param $table |
||
164 | * @param FieldType $type |
||
165 | */ |
||
166 | View Code Duplication | public function restoreColumn($table, FieldType $type) |
|
181 | } |
||
182 |
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.