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 |
||
24 | class UpdateQuery extends AbstractQuery |
||
25 | { |
||
26 | use Executable; |
||
27 | use Limit; |
||
28 | use OrderBy; |
||
29 | use Where; |
||
30 | |||
31 | /** |
||
32 | * @var FromStatement |
||
33 | */ |
||
34 | protected $table; |
||
35 | |||
36 | /** |
||
37 | * @var SetStatement |
||
38 | */ |
||
39 | protected $set; |
||
40 | |||
41 | View Code Duplication | public function __construct() |
|
49 | |||
50 | /** |
||
51 | * Sets the table for the query. |
||
52 | * |
||
53 | * @param string $table table name |
||
54 | * |
||
55 | * @return self |
||
56 | */ |
||
57 | public function table($table) |
||
63 | |||
64 | /** |
||
65 | * Sets the values for the query. |
||
66 | * |
||
67 | * @return self |
||
68 | */ |
||
69 | public function values(array $values) |
||
75 | |||
76 | /** |
||
77 | * Gets the table name for the query. |
||
78 | * |
||
79 | * @return FromStatement |
||
80 | */ |
||
81 | public function getTable() |
||
85 | |||
86 | /** |
||
87 | * Gets the values for the query. |
||
88 | * |
||
89 | * @return SetStatement |
||
90 | */ |
||
91 | public function getSet() |
||
95 | |||
96 | /** |
||
97 | * Generates the raw SQL string for the query. |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | public function build() |
||
118 | |||
119 | public function __clone() |
||
127 | } |
||
128 |