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 |
||
33 | class Driver extends DriverAbstract |
||
34 | { |
||
35 | /** |
||
36 | * the connection link |
||
37 | * |
||
38 | * @var \mysqli |
||
39 | * @access protected |
||
40 | */ |
||
41 | protected $link; |
||
42 | |||
43 | /** |
||
44 | * Default mysqli attributes |
||
45 | * |
||
46 | * @var array |
||
47 | * @access protected |
||
48 | */ |
||
49 | protected $attributes = [ |
||
50 | 'MYSQLI_OPT_CONNECT_TIMEOUT' => 300, |
||
51 | 'MYSQLI_OPT_LOCAL_INFILE' => true, |
||
52 | 'MYSQLI_INIT_COMMAND' => '', |
||
53 | ]; |
||
54 | |||
55 | /** |
||
56 | * Driver constructor |
||
57 | * |
||
58 | * @param array $connectInfo |
||
59 | * @param StatementInterface $statementPrototype |
||
60 | * @throws InvalidArgumentException if link type not right |
||
61 | * @throws LogicException driver specific extension not loaded |
||
62 | * @access public |
||
63 | */ |
||
64 | public function __construct( |
||
73 | |||
74 | /** |
||
75 | * {@inheritDoc} |
||
76 | */ |
||
77 | protected function extensionLoaded()/*# : bool */ |
||
81 | |||
82 | /** |
||
83 | * {@inheritDoc} |
||
84 | */ |
||
85 | protected function realLastId($name) |
||
89 | |||
90 | /** |
||
91 | * {@inheritDoc} |
||
92 | */ |
||
93 | protected function realQuote( |
||
99 | |||
100 | /** |
||
101 | * {@inheritDoc} |
||
102 | */ |
||
103 | protected function realConnect(array $parameters) |
||
129 | |||
130 | /** |
||
131 | * Disconnect the \PDO link |
||
132 | * |
||
133 | * {@inheritDoc} |
||
134 | */ |
||
135 | protected function realDisconnect() |
||
139 | |||
140 | /** |
||
141 | * {@inheritDoc} |
||
142 | */ |
||
143 | protected function realPing()/*# : bool */ |
||
147 | |||
148 | /** |
||
149 | * {@inheritDoc} |
||
150 | */ |
||
151 | View Code Duplication | protected function realSetAttribute(/*# string */ $attribute, $value) |
|
161 | |||
162 | /** |
||
163 | * {@inheritDoc} |
||
164 | */ |
||
165 | protected function realGetAttribute(/*# string */ $attribute) |
||
172 | |||
173 | /** |
||
174 | * {@inheritDoc} |
||
175 | */ |
||
176 | protected function realBegin() |
||
181 | |||
182 | /** |
||
183 | * {@inheritDoc} |
||
184 | */ |
||
185 | protected function realCommit() |
||
191 | |||
192 | /** |
||
193 | * {@inheritDoc} |
||
194 | */ |
||
195 | protected function realRollback() |
||
201 | |||
202 | /** |
||
203 | * |
||
204 | * @param \mysqli $link |
||
205 | * @throws LogicException if failed |
||
206 | * @access protected |
||
207 | */ |
||
208 | protected function isConenctFailed(\mysqli $link) |
||
221 | |||
222 | /** |
||
223 | * Set charset |
||
224 | * |
||
225 | * @param \mysqli $link |
||
226 | * @param array $params |
||
227 | * @access protected |
||
228 | */ |
||
229 | protected function setCharset(\mysqli $link, array $params) |
||
235 | |||
236 | /** |
||
237 | * Is attribute defined ? |
||
238 | * |
||
239 | * @param string $attribute |
||
240 | * @throws LogicException |
||
241 | * @access protected |
||
242 | */ |
||
243 | protected function checkAttribute(/*# string */ $attribute) |
||
252 | } |
||
253 |