Complex classes like AdapterWrapper 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 AdapterWrapper, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
47 | abstract class AdapterWrapper implements AdapterInterface, WrapperInterface |
||
48 | { |
||
49 | /** |
||
50 | * @var AdapterInterface |
||
51 | */ |
||
52 | protected $adapter; |
||
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | 36 | public function __construct(AdapterInterface $adapter) |
|
61 | |||
62 | /** |
||
63 | * {@inheritdoc} |
||
64 | */ |
||
65 | 36 | public function setAdapter(AdapterInterface $adapter) |
|
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | 24 | public function getAdapter() |
|
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | public function setOptions(array $options) |
||
87 | |||
88 | /** |
||
89 | * {@inheritdoc} |
||
90 | */ |
||
91 | 2 | public function getOptions() |
|
95 | |||
96 | /** |
||
97 | * {@inheritdoc} |
||
98 | */ |
||
99 | 8 | public function hasOption($name) |
|
103 | |||
104 | /** |
||
105 | * {@inheritdoc} |
||
106 | */ |
||
107 | 19 | public function getOption($name) |
|
111 | |||
112 | /** |
||
113 | * {@inheritdoc} |
||
114 | */ |
||
115 | 5 | public function setInput(InputInterface $input) |
|
116 | { |
||
117 | 5 | $this->adapter->setInput($input); |
|
118 | 5 | return $this; |
|
119 | } |
||
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | public function getInput() |
||
125 | { |
||
126 | return $this->adapter->getInput(); |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | 5 | public function setOutput(OutputInterface $output) |
|
137 | |||
138 | /** |
||
139 | * {@inheritdoc} |
||
140 | */ |
||
141 | 5 | public function getOutput() |
|
145 | |||
146 | /** |
||
147 | * {@inheritdoc} |
||
148 | */ |
||
149 | public function connect() |
||
153 | |||
154 | /** |
||
155 | * {@inheritdoc} |
||
156 | */ |
||
157 | 5 | public function disconnect() |
|
161 | |||
162 | /** |
||
163 | * {@inheritdoc} |
||
164 | */ |
||
165 | 2 | public function execute($sql) |
|
169 | |||
170 | /** |
||
171 | * {@inheritdoc} |
||
172 | */ |
||
173 | public function query($sql) |
||
177 | |||
178 | /** |
||
179 | * {@inheritdoc} |
||
180 | */ |
||
181 | public function insert(Table $table, $row) |
||
185 | |||
186 | /** |
||
187 | * {@inheritdoc} |
||
188 | */ |
||
189 | 3 | public function bulkinsert(Table $table, $rows) |
|
193 | |||
194 | /** |
||
195 | * {@inheritdoc} |
||
196 | */ |
||
197 | public function fetchRow($sql) |
||
201 | |||
202 | /** |
||
203 | * {@inheritdoc} |
||
204 | */ |
||
205 | 1 | public function fetchAll($sql) |
|
209 | |||
210 | /** |
||
211 | * {@inheritdoc} |
||
212 | */ |
||
213 | 5 | public function getVersions() |
|
217 | |||
218 | /** |
||
219 | * {@inheritdoc} |
||
220 | */ |
||
221 | 5 | public function getVersionLog() |
|
222 | { |
||
223 | 5 | return $this->getAdapter()->getVersionLog(); |
|
224 | } |
||
225 | |||
226 | /** |
||
227 | * {@inheritdoc} |
||
228 | */ |
||
229 | 5 | public function migrated(MigrationInterface $migration, $direction, $startTime, $endTime) |
|
234 | |||
235 | /** |
||
236 | * @inheritDoc |
||
237 | */ |
||
238 | 1 | public function toggleBreakpoint(MigrationInterface $migration) |
|
239 | { |
||
240 | 1 | $this->getAdapter()->toggleBreakpoint($migration); |
|
241 | 1 | return $this; |
|
242 | } |
||
243 | |||
244 | /** |
||
245 | * @inheritDoc |
||
246 | */ |
||
247 | 1 | public function resetAllBreakpoints() |
|
248 | { |
||
249 | 1 | return $this->getAdapter()->resetAllBreakpoints(); |
|
250 | } |
||
251 | |||
252 | /** |
||
253 | * {@inheritdoc} |
||
254 | */ |
||
255 | public function hasSchemaTable() |
||
259 | |||
260 | /** |
||
261 | * {@inheritdoc} |
||
262 | */ |
||
263 | public function createSchemaTable() |
||
267 | |||
268 | /** |
||
269 | * {@inheritdoc} |
||
270 | */ |
||
271 | public function getColumnTypes() |
||
275 | |||
276 | /** |
||
277 | * {@inheritdoc} |
||
278 | */ |
||
279 | 4 | public function isValidColumnType(Column $column) |
|
283 | |||
284 | /** |
||
285 | * {@inheritdoc} |
||
286 | */ |
||
287 | 5 | public function hasTransactions() |
|
291 | |||
292 | /** |
||
293 | * {@inheritdoc} |
||
294 | */ |
||
295 | 5 | public function beginTransaction() |
|
299 | |||
300 | /** |
||
301 | * {@inheritdoc} |
||
302 | */ |
||
303 | 5 | public function commitTransaction() |
|
307 | |||
308 | /** |
||
309 | * {@inheritdoc} |
||
310 | */ |
||
311 | public function rollbackTransaction() |
||
315 | |||
316 | /** |
||
317 | * {@inheritdoc} |
||
318 | */ |
||
319 | public function quoteTableName($tableName) |
||
323 | |||
324 | /** |
||
325 | * {@inheritdoc} |
||
326 | */ |
||
327 | public function quoteColumnName($columnName) |
||
331 | |||
332 | /** |
||
333 | * {@inheritdoc} |
||
334 | */ |
||
335 | 5 | public function hasTable($tableName) |
|
339 | |||
340 | /** |
||
341 | * {@inheritdoc} |
||
342 | */ |
||
343 | 6 | public function createTable(Table $table) |
|
347 | |||
348 | /** |
||
349 | * {@inheritdoc} |
||
350 | */ |
||
351 | 4 | public function renameTable($tableName, $newTableName) |
|
355 | |||
356 | /** |
||
357 | * {@inheritdoc} |
||
358 | */ |
||
359 | 4 | public function dropTable($tableName) |
|
363 | |||
364 | /** |
||
365 | * {@inheritdoc} |
||
366 | */ |
||
367 | public function truncateTable($tableName) |
||
371 | |||
372 | /** |
||
373 | * {@inheritdoc} |
||
374 | */ |
||
375 | 1 | public function getColumns($tableName) |
|
379 | |||
380 | /** |
||
381 | * {@inheritdoc} |
||
382 | */ |
||
383 | 4 | public function hasColumn($tableName, $columnName) |
|
387 | |||
388 | /** |
||
389 | * {@inheritdoc} |
||
390 | */ |
||
391 | 4 | public function addColumn(Table $table, Column $column) |
|
395 | |||
396 | /** |
||
397 | * {@inheritdoc} |
||
398 | */ |
||
399 | 4 | public function renameColumn($tableName, $columnName, $newColumnName) |
|
403 | |||
404 | /** |
||
405 | * {@inheritdoc} |
||
406 | */ |
||
407 | 1 | public function changeColumn($tableName, $columnName, Column $newColumn) |
|
411 | |||
412 | /** |
||
413 | * {@inheritdoc} |
||
414 | */ |
||
415 | 4 | public function dropColumn($tableName, $columnName) |
|
419 | |||
420 | /** |
||
421 | * {@inheritdoc} |
||
422 | */ |
||
423 | 1 | public function hasIndex($tableName, $columns) |
|
427 | |||
428 | /** |
||
429 | * {@inheritdoc} |
||
430 | */ |
||
431 | public function hasIndexByName($tableName, $indexName) |
||
435 | |||
436 | /** |
||
437 | * {@inheritdoc} |
||
438 | */ |
||
439 | public function addIndex(Table $table, Index $index) |
||
443 | |||
444 | /** |
||
445 | * {@inheritdoc} |
||
446 | */ |
||
447 | 1 | public function dropIndex($tableName, $columns) |
|
451 | |||
452 | /** |
||
453 | * {@inheritdoc} |
||
454 | */ |
||
455 | 1 | public function dropIndexByName($tableName, $indexName) |
|
459 | |||
460 | /** |
||
461 | * {@inheritdoc} |
||
462 | */ |
||
463 | 4 | public function hasForeignKey($tableName, $columns, $constraint = null) |
|
467 | |||
468 | /** |
||
469 | * {@inheritdoc} |
||
470 | */ |
||
471 | 4 | public function addForeignKey(Table $table, ForeignKey $foreignKey) |
|
475 | |||
476 | /** |
||
477 | * {@inheritdoc} |
||
478 | */ |
||
479 | 4 | public function dropForeignKey($tableName, $columns, $constraint = null) |
|
483 | |||
484 | /** |
||
485 | * {@inheritdoc} |
||
486 | */ |
||
487 | public function getSqlType($type, $limit = null) |
||
491 | |||
492 | /** |
||
493 | * {@inheritdoc} |
||
494 | */ |
||
495 | 5 | public function createDatabase($name, $options = []) |
|
499 | |||
500 | /** |
||
501 | * {@inheritdoc} |
||
502 | */ |
||
503 | public function hasDatabase($name) |
||
507 | |||
508 | /** |
||
509 | * {@inheritdoc} |
||
510 | */ |
||
511 | 5 | public function dropDatabase($name) |
|
515 | |||
516 | /** |
||
517 | * {@inheritdoc} |
||
518 | */ |
||
519 | public function createSchema($schemaName = 'public') |
||
523 | |||
524 | /** |
||
525 | * {@inheritdoc} |
||
526 | */ |
||
527 | public function dropSchema($schemaName) |
||
531 | |||
532 | /** |
||
533 | * {@inheritdoc} |
||
534 | */ |
||
535 | public function castToBool($value) |
||
536 | { |
||
537 | return $this->getAdapter()->castToBool($value); |
||
538 | } |
||
539 | |||
540 | /** |
||
541 | * {@inheritdoc} |
||
542 | */ |
||
543 | public function getConnection() |
||
547 | } |
||
548 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.