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 |
||
23 | class UpdateQuery extends AbstractQuery |
||
24 | { |
||
25 | use Executable, Limit, OrderBy, Where; |
||
26 | |||
27 | /** |
||
28 | * @var FromStatement |
||
29 | */ |
||
30 | protected $table; |
||
31 | |||
32 | /** |
||
33 | * @var SetStatement |
||
34 | */ |
||
35 | protected $set; |
||
36 | |||
37 | View Code Duplication | public function __construct() |
|
45 | |||
46 | /** |
||
47 | * Sets the table for the query. |
||
48 | * |
||
49 | * @param string $table table name |
||
50 | * |
||
51 | * @return self |
||
52 | */ |
||
53 | public function table($table) |
||
59 | |||
60 | /** |
||
61 | * Sets the values for the query. |
||
62 | * |
||
63 | * @param array $values |
||
64 | * |
||
65 | * @return self |
||
66 | */ |
||
67 | public function values(array $values) |
||
73 | |||
74 | /** |
||
75 | * Gets the table name for the query. |
||
76 | * |
||
77 | * @return FromStatement |
||
78 | */ |
||
79 | public function getTable() |
||
83 | |||
84 | /** |
||
85 | * Gets the values for the query. |
||
86 | * |
||
87 | * @return array |
||
88 | */ |
||
89 | public function getSet() |
||
93 | |||
94 | /** |
||
95 | * Generates the raw SQL string for the query. |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | public function build() |
||
115 | |||
116 | public function __clone() |
||
124 | } |
||
125 |
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.