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 |
||
30 | class AddColumn extends Action |
||
31 | { |
||
32 | |||
33 | /** |
||
34 | * The column to add |
||
35 | * |
||
36 | * @var Column |
||
37 | */ |
||
38 | protected $column; |
||
39 | |||
40 | /** |
||
41 | * Constructo |
||
42 | * |
||
43 | * @param Table $table The table to add the column to |
||
44 | * @param Column $column The column to add |
||
45 | */ |
||
46 | public function __construct(Table $table, Column $column) |
||
51 | |||
52 | /** |
||
53 | * Returns a new AddColumn object after assembling the given commands |
||
54 | * |
||
55 | * @param Table $table The table to add the column to |
||
56 | * @param mixed $columnName The column name |
||
57 | * @param mixed $type The column type |
||
58 | * @param mixed $options The column options |
||
59 | */ |
||
60 | View Code Duplication | public static function build(Table $table, $columnName, $type = null, $options = []) |
|
69 | |||
70 | /** |
||
71 | * Returns the column to be added |
||
72 | * |
||
73 | * @return Column |
||
74 | */ |
||
75 | public function getColumn() |
||
79 | } |
||
80 |
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.