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 |
||
31 | class SQLSrvConnection implements Connection, ServerInfoAwareConnection |
||
32 | { |
||
33 | /** |
||
34 | * @var resource |
||
35 | */ |
||
36 | protected $conn; |
||
37 | |||
38 | /** |
||
39 | * @var \Doctrine\DBAL\Driver\SQLSrv\LastInsertId |
||
40 | */ |
||
41 | protected $lastInsertId; |
||
42 | |||
43 | /** |
||
44 | * @param string $serverName |
||
45 | * @param array $connectionOptions |
||
46 | * |
||
47 | * @throws \Doctrine\DBAL\Driver\SQLSrv\SQLSrvException |
||
48 | */ |
||
49 | public function __construct($serverName, $connectionOptions) |
||
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | public function getServerVersion() |
||
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | public function requiresQueryForServerVersion() |
||
80 | |||
81 | /** |
||
82 | * {@inheritDoc} |
||
83 | */ |
||
84 | public function prepare($sql) |
||
88 | |||
89 | /** |
||
90 | * {@inheritDoc} |
||
91 | */ |
||
92 | View Code Duplication | public function query() |
|
101 | |||
102 | /** |
||
103 | * {@inheritDoc} |
||
104 | * @license New BSD, code from Zend Framework |
||
105 | */ |
||
106 | View Code Duplication | public function quote($value, $type=\PDO::PARAM_STR) |
|
116 | |||
117 | /** |
||
118 | * {@inheritDoc} |
||
119 | */ |
||
120 | public function exec($statement) |
||
142 | |||
143 | /** |
||
144 | * {@inheritDoc} |
||
145 | */ |
||
146 | public function lastInsertId($name = null) |
||
157 | |||
158 | /** |
||
159 | * {@inheritDoc} |
||
160 | */ |
||
161 | public function beginTransaction() |
||
167 | |||
168 | /** |
||
169 | * {@inheritDoc} |
||
170 | */ |
||
171 | public function commit() |
||
177 | |||
178 | /** |
||
179 | * {@inheritDoc} |
||
180 | */ |
||
181 | public function rollBack() |
||
187 | |||
188 | /** |
||
189 | * {@inheritDoc} |
||
190 | */ |
||
191 | View Code Duplication | public function errorCode() |
|
200 | |||
201 | /** |
||
202 | * {@inheritDoc} |
||
203 | */ |
||
204 | public function errorInfo() |
||
208 | } |
||
209 |
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.