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) |
||
126 | |||
127 | /** |
||
128 | * Disconnect the \PDO link |
||
129 | * |
||
130 | * {@inheritDoc} |
||
131 | */ |
||
132 | protected function realDisconnect() |
||
136 | |||
137 | /** |
||
138 | * {@inheritDoc} |
||
139 | */ |
||
140 | protected function realPing()/*# : bool */ |
||
144 | |||
145 | /** |
||
146 | * {@inheritDoc} |
||
147 | */ |
||
148 | View Code Duplication | protected function realSetAttribute(/*# string */ $attribute, $value) |
|
158 | |||
159 | /** |
||
160 | * {@inheritDoc} |
||
161 | */ |
||
162 | protected function realGetAttribute(/*# string */ $attribute) |
||
169 | |||
170 | /** |
||
171 | * {@inheritDoc} |
||
172 | */ |
||
173 | protected function realBegin() |
||
178 | |||
179 | /** |
||
180 | * {@inheritDoc} |
||
181 | */ |
||
182 | protected function realCommit() |
||
188 | |||
189 | /** |
||
190 | * {@inheritDoc} |
||
191 | */ |
||
192 | protected function realRollback() |
||
198 | |||
199 | /** |
||
200 | * Fill connect params with defaults |
||
201 | * |
||
202 | * @param array $params |
||
203 | * @return array |
||
204 | * @access protected |
||
205 | */ |
||
206 | protected function fixParams(array $params)/*# : array */ |
||
217 | |||
218 | /** |
||
219 | * |
||
220 | * @param \mysqli $link |
||
221 | * @throws LogicException if failed |
||
222 | * @access protected |
||
223 | */ |
||
224 | protected function isConenctFailed(\mysqli $link) |
||
237 | |||
238 | /** |
||
239 | * Set charset |
||
240 | * |
||
241 | * @param \mysqli $link |
||
242 | * @param array $params |
||
243 | * @access protected |
||
244 | */ |
||
245 | protected function setCharset(\mysqli $link, array $params) |
||
251 | |||
252 | /** |
||
253 | * Is attribute defined ? |
||
254 | * |
||
255 | * @param string $attribute |
||
256 | * @throws LogicException |
||
257 | * @access protected |
||
258 | */ |
||
259 | protected function checkAttribute(/*# string */ $attribute) |
||
268 | } |
||
269 |