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) |
||
120 | |||
121 | /** |
||
122 | * Disconnect the \PDO link |
||
123 | * |
||
124 | * {@inheritDoc} |
||
125 | */ |
||
126 | protected function realDisconnect() |
||
130 | |||
131 | /** |
||
132 | * {@inheritDoc} |
||
133 | */ |
||
134 | protected function realPing()/*# : bool */ |
||
138 | |||
139 | /** |
||
140 | * {@inheritDoc} |
||
141 | */ |
||
142 | View Code Duplication | protected function realSetAttribute(/*# string */ $attribute, $value) |
|
152 | |||
153 | /** |
||
154 | * {@inheritDoc} |
||
155 | */ |
||
156 | protected function realGetAttribute(/*# string */ $attribute) |
||
163 | |||
164 | /** |
||
165 | * {@inheritDoc} |
||
166 | */ |
||
167 | protected function realBegin() |
||
172 | |||
173 | /** |
||
174 | * {@inheritDoc} |
||
175 | */ |
||
176 | protected function realCommit() |
||
182 | |||
183 | /** |
||
184 | * {@inheritDoc} |
||
185 | */ |
||
186 | protected function realRollback() |
||
192 | |||
193 | /** |
||
194 | * Fill connect params with defaults |
||
195 | * |
||
196 | * @param array $params |
||
197 | * @return array |
||
198 | * @access protected |
||
199 | */ |
||
200 | protected function fixParams(array $params)/*# : array */ |
||
211 | |||
212 | /** |
||
213 | * |
||
214 | * @param \mysqli $link |
||
215 | * @throws LogicException if failed |
||
216 | * @access protected |
||
217 | */ |
||
218 | protected function isConenctFailed(\mysqli $link) |
||
231 | |||
232 | /** |
||
233 | * Set charset |
||
234 | * |
||
235 | * @param \mysqli $link |
||
236 | * @param array $params |
||
237 | * @access protected |
||
238 | */ |
||
239 | protected function setCharset(\mysqli $link, array $params) |
||
245 | |||
246 | /** |
||
247 | * Is attribute defined ? |
||
248 | * |
||
249 | * @param string $attribute |
||
250 | * @throws LogicException |
||
251 | * @access protected |
||
252 | */ |
||
253 | protected function checkAttribute(/*# string */ $attribute) |
||
262 | } |
||
263 |