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 |
||
45 | abstract class AdapterWrapper implements AdapterInterface, WrapperInterface |
||
46 | { |
||
47 | /** |
||
48 | * @var \Phinx\Db\Adapter\AdapterInterface |
||
49 | */ |
||
50 | protected $adapter; |
||
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | public function __construct(AdapterInterface $adapter) |
||
59 | 36 | ||
60 | 36 | /** |
|
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | public function setAdapter(AdapterInterface $adapter) |
||
69 | |||
70 | /** |
||
71 | * {@inheritdoc} |
||
72 | */ |
||
73 | public function getAdapter() |
||
77 | |||
78 | /** |
||
79 | * {@inheritdoc} |
||
80 | */ |
||
81 | 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 | ||
119 | return $this; |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * {@inheritdoc} |
||
124 | */ |
||
125 | public function getInput() |
||
126 | { |
||
127 | return $this->adapter->getInput(); |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * {@inheritdoc} |
||
132 | 5 | */ |
|
133 | public function setOutput(OutputInterface $output) |
||
139 | |||
140 | /** |
||
141 | 5 | * {@inheritdoc} |
|
142 | */ |
||
143 | 5 | public function getOutput() |
|
147 | |||
148 | /** |
||
149 | * {@inheritdoc} |
||
150 | */ |
||
151 | public function connect() |
||
155 | |||
156 | /** |
||
157 | 5 | * {@inheritdoc} |
|
158 | */ |
||
159 | 5 | public function disconnect() |
|
163 | |||
164 | /** |
||
165 | 2 | * {@inheritdoc} |
|
166 | */ |
||
167 | 2 | public function execute($sql) |
|
171 | |||
172 | /** |
||
173 | * {@inheritdoc} |
||
174 | */ |
||
175 | public function query($sql) |
||
179 | |||
180 | /** |
||
181 | * {@inheritdoc} |
||
182 | */ |
||
183 | public function insert(Table $table, $row) |
||
187 | |||
188 | /** |
||
189 | 3 | * {@inheritdoc} |
|
190 | */ |
||
191 | 3 | public function bulkinsert(Table $table, $rows) |
|
195 | |||
196 | /** |
||
197 | * {@inheritdoc} |
||
198 | */ |
||
199 | public function fetchRow($sql) |
||
203 | |||
204 | /** |
||
205 | 1 | * {@inheritdoc} |
|
206 | */ |
||
207 | 1 | public function fetchAll($sql) |
|
211 | |||
212 | /** |
||
213 | 5 | * {@inheritdoc} |
|
214 | */ |
||
215 | 5 | public function getVersions() |
|
219 | |||
220 | /** |
||
221 | 5 | * {@inheritdoc} |
|
222 | */ |
||
223 | 5 | public function getVersionLog() |
|
224 | { |
||
225 | return $this->getAdapter()->getVersionLog(); |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | 5 | * {@inheritdoc} |
|
230 | */ |
||
231 | 5 | public function migrated(MigrationInterface $migration, $direction, $startTime, $endTime) |
|
237 | |||
238 | 1 | /** |
|
239 | * {@inheritdoc} |
||
240 | 1 | */ |
|
241 | 1 | public function toggleBreakpoint(MigrationInterface $migration) |
|
242 | { |
||
243 | $this->getAdapter()->toggleBreakpoint($migration); |
||
244 | |||
245 | return $this; |
||
246 | } |
||
247 | 1 | ||
248 | /** |
||
249 | 1 | * {@inheritdoc} |
|
250 | */ |
||
251 | public function resetAllBreakpoints() |
||
252 | { |
||
253 | return $this->getAdapter()->resetAllBreakpoints(); |
||
254 | } |
||
255 | |||
256 | /** |
||
257 | * {@inheritdoc} |
||
258 | */ |
||
259 | public function setBreakpoint(MigrationInterface $migration) |
||
265 | |||
266 | /** |
||
267 | * {@inheritdoc} |
||
268 | */ |
||
269 | public function unsetBreakpoint(MigrationInterface $migration) |
||
275 | |||
276 | /** |
||
277 | * {@inheritdoc} |
||
278 | */ |
||
279 | 4 | public function hasSchemaTable() |
|
283 | |||
284 | /** |
||
285 | * {@inheritdoc} |
||
286 | */ |
||
287 | 5 | public function createSchemaTable() |
|
291 | |||
292 | /** |
||
293 | * {@inheritdoc} |
||
294 | */ |
||
295 | 5 | public function getColumnTypes() |
|
299 | |||
300 | /** |
||
301 | * {@inheritdoc} |
||
302 | */ |
||
303 | 5 | public function isValidColumnType(Column $column) |
|
307 | |||
308 | /** |
||
309 | * {@inheritdoc} |
||
310 | */ |
||
311 | public function hasTransactions() |
||
315 | |||
316 | /** |
||
317 | * {@inheritdoc} |
||
318 | */ |
||
319 | public function beginTransaction() |
||
323 | |||
324 | /** |
||
325 | * {@inheritdoc} |
||
326 | */ |
||
327 | public function commitTransaction() |
||
331 | |||
332 | /** |
||
333 | * {@inheritdoc} |
||
334 | */ |
||
335 | 5 | public function rollbackTransaction() |
|
339 | |||
340 | /** |
||
341 | * {@inheritdoc} |
||
342 | */ |
||
343 | 6 | public function quoteTableName($tableName) |
|
347 | |||
348 | /** |
||
349 | * {@inheritdoc} |
||
350 | */ |
||
351 | 4 | public function quoteColumnName($columnName) |
|
355 | |||
356 | /** |
||
357 | * {@inheritdoc} |
||
358 | */ |
||
359 | 4 | public function hasTable($tableName) |
|
363 | |||
364 | /** |
||
365 | * {@inheritdoc} |
||
366 | */ |
||
367 | public function createTable(Table $table, array $columns = [], array $indexes = []) |
||
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 hasIndex($tableName, $columns) |
|
395 | |||
396 | /** |
||
397 | * {@inheritdoc} |
||
398 | */ |
||
399 | 4 | public function hasIndexByName($tableName, $indexName) |
|
403 | |||
404 | /** |
||
405 | * {@inheritdoc} |
||
406 | */ |
||
407 | 1 | public function hasPrimaryKey($tableName, $columns, $constraint = null) |
|
411 | |||
412 | /** |
||
413 | * {@inheritdoc} |
||
414 | */ |
||
415 | 4 | public function hasForeignKey($tableName, $columns, $constraint = null) |
|
419 | |||
420 | /** |
||
421 | * {@inheritdoc} |
||
422 | */ |
||
423 | 1 | public function getSqlType($type, $limit = null) |
|
427 | |||
428 | /** |
||
429 | * {@inheritdoc} |
||
430 | */ |
||
431 | public function createDatabase($name, $options = []) |
||
435 | |||
436 | /** |
||
437 | * {@inheritdoc} |
||
438 | */ |
||
439 | public function hasDatabase($name) |
||
443 | |||
444 | /** |
||
445 | * {@inheritdoc} |
||
446 | */ |
||
447 | 1 | public function dropDatabase($name) |
|
451 | |||
452 | /** |
||
453 | * {@inheritdoc} |
||
454 | */ |
||
455 | 1 | public function createSchema($schemaName = 'public') |
|
459 | |||
460 | /** |
||
461 | * {@inheritdoc} |
||
462 | */ |
||
463 | 4 | public function dropSchema($schemaName) |
|
467 | |||
468 | /** |
||
469 | * {@inheritdoc} |
||
470 | */ |
||
471 | 4 | public function truncateTable($tableName) |
|
475 | |||
476 | /** |
||
477 | * {@inheritdoc} |
||
478 | */ |
||
479 | 4 | public function castToBool($value) |
|
480 | { |
||
481 | 4 | return $this->getAdapter()->castToBool($value); |
|
482 | 4 | } |
|
483 | |||
484 | /** |
||
485 | * {@inheritdoc} |
||
486 | */ |
||
487 | public function getConnection() |
||
491 | |||
492 | /** |
||
493 | * {@inheritdoc} |
||
494 | */ |
||
495 | 5 | public function executeActions(Table $table, array $actions) |
|
499 | |||
500 | /** |
||
501 | * {@inheritdoc} |
||
502 | */ |
||
503 | public function getQueryBuilder() |
||
507 | } |
||
508 |
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.