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 |
||
44 | class ColRef implements NodeInterface |
||
45 | { |
||
46 | private $table; |
||
47 | |||
48 | /** |
||
49 | * Returns the table name. |
||
50 | * |
||
51 | * @return string |
||
52 | */ |
||
53 | public function getTable() |
||
57 | |||
58 | /** |
||
59 | * Sets the table name. |
||
60 | * |
||
61 | * @Important |
||
62 | * |
||
63 | * @param string $table |
||
64 | */ |
||
65 | public function setTable($table) |
||
69 | |||
70 | private $column; |
||
71 | |||
72 | /** |
||
73 | * Returns the column name. |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | public function getColumn() |
||
81 | |||
82 | /** |
||
83 | * Sets the column name. |
||
84 | * |
||
85 | * @Important |
||
86 | * |
||
87 | * @param string $column |
||
88 | */ |
||
89 | public function setColumn($column) |
||
93 | |||
94 | private $alias; |
||
95 | |||
96 | /** |
||
97 | * Returns the alias. |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | public function getAlias() |
||
105 | |||
106 | /** |
||
107 | * Sets the alias. |
||
108 | * |
||
109 | * @Important |
||
110 | * |
||
111 | * @param string $alias |
||
112 | */ |
||
113 | public function setAlias($alias) |
||
117 | |||
118 | private $direction; |
||
119 | |||
120 | /** |
||
121 | * Returns the direction. |
||
122 | * |
||
123 | * @return string |
||
124 | */ |
||
125 | public function getDirection() |
||
129 | |||
130 | /** |
||
131 | * Sets the direction. |
||
132 | * |
||
133 | * @Important |
||
134 | * |
||
135 | * @param string $direction |
||
136 | */ |
||
137 | public function setDirection($direction) |
||
141 | |||
142 | /** |
||
143 | * Returns a Mouf instance descriptor describing this object. |
||
144 | * |
||
145 | * @param MoufManager $moufManager |
||
146 | * |
||
147 | * @return MoufInstanceDescriptor |
||
148 | */ |
||
149 | View Code Duplication | public function toInstanceDescriptor(MoufManager $moufManager) |
|
159 | |||
160 | /** |
||
161 | * Renders the object as a SQL string. |
||
162 | * |
||
163 | * @param Connection $dbConnection |
||
164 | * @param array $parameters |
||
165 | * @param number $indent |
||
166 | * @param int $conditionsMode |
||
167 | * |
||
168 | * @return string |
||
169 | */ |
||
170 | public function toSql(array $parameters = array(), Connection $dbConnection = null, $indent = 0, $conditionsMode = self::CONDITION_APPLY) |
||
190 | |||
191 | /** |
||
192 | * Walks the tree of nodes, calling the visitor passed in parameter. |
||
193 | * |
||
194 | * @param VisitorInterface $visitor |
||
195 | */ |
||
196 | View Code Duplication | public function walk(VisitorInterface $visitor) |
|
206 | } |
||
207 |
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.