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 |
||
9 | final class DoctrineDbalExecutorResult implements Statement |
||
10 | { |
||
11 | private $statement; |
||
12 | |||
13 | public function __construct(Statement $statement) |
||
17 | |||
18 | View Code Duplication | public function getSingleScalarResult() |
|
32 | |||
33 | public function getSingleScalarResultOrDefault($default) |
||
41 | |||
42 | public function getSingleScalarResultOrNull() |
||
46 | |||
47 | public function getScalarResult() |
||
57 | |||
58 | public function getScalarResultOrDefault($default) |
||
68 | |||
69 | public function getScalarResultOrNull() |
||
73 | |||
74 | View Code Duplication | public function getSingleRowResult() |
|
88 | |||
89 | public function getSingleRowOrDefault($default) |
||
97 | |||
98 | public function getSingleRowOrNull() |
||
102 | |||
103 | /** |
||
104 | * {@inheritdoc} |
||
105 | */ |
||
106 | public function closeCursor() |
||
110 | |||
111 | /** |
||
112 | * {@inheritdoc} |
||
113 | */ |
||
114 | public function columnCount() |
||
118 | |||
119 | /** |
||
120 | * {@inheritdoc} |
||
121 | */ |
||
122 | public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) |
||
126 | |||
127 | /** |
||
128 | * {@inheritdoc} |
||
129 | */ |
||
130 | public function fetch($fetchMode = null) |
||
134 | |||
135 | /** |
||
136 | * {@inheritdoc} |
||
137 | */ |
||
138 | public function fetchAll($fetchMode = null) |
||
142 | |||
143 | /** |
||
144 | * {@inheritdoc} |
||
145 | */ |
||
146 | public function fetchColumn($columnIndex = 0) |
||
150 | |||
151 | /** |
||
152 | * {@inheritdoc} |
||
153 | */ |
||
154 | public function bindValue($param, $value, $type = null) |
||
158 | |||
159 | /** |
||
160 | * {@inheritdoc} |
||
161 | */ |
||
162 | public function bindParam($column, &$variable, $type = null, $length = null) |
||
166 | |||
167 | /** |
||
168 | * {@inheritdoc} |
||
169 | */ |
||
170 | public function errorCode() |
||
174 | |||
175 | /** |
||
176 | * {@inheritdoc} |
||
177 | */ |
||
178 | public function errorInfo() |
||
182 | |||
183 | /** |
||
184 | * {@inheritdoc} |
||
185 | */ |
||
186 | public function execute($params = null) |
||
190 | |||
191 | /** |
||
192 | * {@inheritdoc} |
||
193 | */ |
||
194 | public function rowCount() |
||
198 | |||
199 | /** |
||
200 | * {@inheritdoc} |
||
201 | */ |
||
202 | public function __get($name) |
||
206 | |||
207 | /** |
||
208 | * {@inheritdoc} |
||
209 | */ |
||
210 | public function __set($name, $value) |
||
214 | |||
215 | /** |
||
216 | * {@inheritdoc} |
||
217 | */ |
||
218 | public function __isset($name) |
||
222 | |||
223 | /** |
||
224 | * {@inheritdoc} |
||
225 | */ |
||
226 | public function __call($name, $arguments) |
||
230 | } |
||
231 |
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.