Complex classes like Bridge often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Bridge, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
9 | class Bridge |
||
10 | { |
||
11 | /** |
||
12 | * MYSQL_CLIENT_COMPRESS |
||
13 | */ |
||
14 | const CLIENT_COMPRESS = 32; |
||
15 | |||
16 | /** |
||
17 | * MYSQL_CLIENT_SSL |
||
18 | */ |
||
19 | const CLIENT_SSL = 2048; |
||
20 | |||
21 | /** |
||
22 | * MYSQL_CLIENT_INTERACTIVE |
||
23 | */ |
||
24 | const CLIENT_INTERACTIVE = 1024; |
||
25 | |||
26 | |||
27 | /** |
||
28 | * MYSQL_CLIENT_IGNORE_SPACE |
||
29 | */ |
||
30 | const CLIENT_IGNORE_SPACE = 256; |
||
31 | |||
32 | /** |
||
33 | * The database manager instance. |
||
34 | * |
||
35 | * @var Manager |
||
36 | */ |
||
37 | protected $manager; |
||
38 | |||
39 | /** |
||
40 | * Create a new bridge. |
||
41 | * |
||
42 | * @param Manager $manager |
||
43 | */ |
||
44 | public function __construct(Manager $manager) |
||
48 | |||
49 | public function affectedRows(Connection $linkIdentifier = null) |
||
55 | |||
56 | public function clientEncoding(Connection $linkIdentifier = null) |
||
62 | |||
63 | public function close(Connection $linkIdentifier = null) |
||
67 | |||
68 | public function connect($server = null, $username = null, $password = null, $newLink = false, $clientFlags = 0) |
||
78 | |||
79 | protected function parseClientFlags($clientFlags) |
||
101 | |||
102 | public function createDb($databaseName, Connection $linkIdentifier = null) |
||
111 | |||
112 | public function dataSeek() |
||
116 | |||
117 | public function dbName() |
||
121 | |||
122 | public function dbQuery($database, $query, Connection $linkIdentifier = null) |
||
129 | |||
130 | public function dropDb() |
||
134 | |||
135 | /** |
||
136 | * Return the last error number. A value of 0 means no errors. |
||
137 | * |
||
138 | * @param Connection|null $linkIdentifier |
||
139 | * @return int |
||
140 | */ |
||
141 | public function errno(Connection $linkIdentifier = null) |
||
147 | |||
148 | /** |
||
149 | * Return the last error text. |
||
150 | * |
||
151 | * @param Connection|null $linkIdentifier |
||
152 | * @return string |
||
153 | */ |
||
154 | public function error(Connection $linkIdentifier = null) |
||
160 | |||
161 | public function escapeString($unescapedString) |
||
165 | |||
166 | /** |
||
167 | * Fetch the next row from the result as an array. |
||
168 | * |
||
169 | * @param Result $result |
||
170 | * @param int $resultType |
||
171 | * @return bool|array |
||
172 | */ |
||
173 | public function fetchArray(Result $result, $resultType = Result::FETCH_BOTH) |
||
177 | |||
178 | /** |
||
179 | * Fetch the next row as an associative array. |
||
180 | * |
||
181 | * @param Result $result |
||
182 | * @return bool|array |
||
183 | */ |
||
184 | public function fetchAssoc(Result $result) |
||
188 | |||
189 | /** |
||
190 | * Fetch the metadata of a column. |
||
191 | * USE WITH CARE! Accuracy of results is not guaranteed. |
||
192 | * |
||
193 | * @param Result $result |
||
194 | * @param int $fieldOffset |
||
195 | * @return bool|object |
||
196 | * @deprecated |
||
197 | */ |
||
198 | public function fetchField(Result $result, $fieldOffset = 0) |
||
214 | |||
215 | public function fetchLengths(Result $result) |
||
223 | |||
224 | public function fetchObject(Result $result, $className = 'stdClass', array $params = []) |
||
228 | |||
229 | public function fetchRow(Result $result) |
||
233 | |||
234 | public function fieldfFlags() |
||
238 | |||
239 | public function fieldLen() |
||
243 | |||
244 | public function fieldName() |
||
248 | |||
249 | public function fieldSeek() |
||
253 | |||
254 | public function fieldTable() |
||
258 | |||
259 | public function fieldType() |
||
263 | |||
264 | public function freeResult() |
||
268 | |||
269 | public function getClientInfo() |
||
273 | |||
274 | public function getHostInfo() |
||
278 | |||
279 | public function getProtoInfo() |
||
283 | |||
284 | public function getServerInfo(Connection $linkIdentifier = null) |
||
290 | |||
291 | public function info() |
||
295 | |||
296 | public function insertId(Connection $linkIdentifier = null) |
||
302 | |||
303 | public function listDbs() |
||
307 | |||
308 | public function listFields() |
||
312 | |||
313 | public function listProcesses() |
||
317 | |||
318 | public function listTables($database, Connection $linkIdentifier = null) |
||
327 | |||
328 | public function numFields(Result $result) |
||
332 | |||
333 | public function numRows(Result $result) |
||
347 | |||
348 | public function pconnect() |
||
352 | |||
353 | public function ping() |
||
357 | |||
358 | public function query($query, Connection $linkIdentifier = null) |
||
370 | |||
371 | public function realEscapeString($unescapedString, Connection $linkIdentifier = null) |
||
383 | |||
384 | public function result(Result $result, $row, $field = 0) |
||
390 | |||
391 | public function selectDb($databaseName, Connection $linkIdentifier = null) |
||
397 | |||
398 | public function setCharset() |
||
402 | |||
403 | public function stat() |
||
407 | |||
408 | public function tablename() |
||
412 | |||
413 | public function threadId() |
||
417 | |||
418 | public function unbufferedQuery() |
||
422 | } |
||
423 |
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.