Complex classes like DatabaseSchema 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 DatabaseSchema, and based on these observations, apply Extract Interface, too.
1 | <?php declare(strict_types=1); |
||
28 | class DatabaseSchema implements DatabaseSchemaInterface |
||
29 | { |
||
30 | /** Table name */ |
||
31 | const TABLE_CLIENTS = 'oauth_clients'; |
||
32 | |||
33 | /** View name */ |
||
34 | const VIEW_CLIENTS = 'vw_oauth_clients'; |
||
35 | |||
36 | /** Table name */ |
||
37 | const TABLE_CLIENTS_SCOPES = 'oauth_clients_scopes'; |
||
38 | |||
39 | /** Table name */ |
||
40 | const TABLE_REDIRECT_URIS = 'oauth_redirect_uris'; |
||
41 | |||
42 | /** Table name */ |
||
43 | const TABLE_SCOPES = 'oauth_scopes'; |
||
44 | |||
45 | /** Table name */ |
||
46 | const TABLE_TOKENS = 'oauth_tokens'; |
||
47 | |||
48 | /** View name */ |
||
49 | const VIEW_TOKENS = 'vw_oauth_tokens'; |
||
50 | |||
51 | /** Table name */ |
||
52 | const TABLE_TOKENS_SCOPES = 'oauth_tokens_scopes'; |
||
53 | |||
54 | /** View name */ |
||
55 | const VIEW_USERS = 'vw_oauth_users'; |
||
56 | |||
57 | /** Field name */ |
||
58 | const CLIENTS_SCOPES_FIELD_ID = 'clients_scopes_id'; |
||
59 | |||
60 | /** Field name */ |
||
61 | const TOKENS_SCOPES_FIELD_ID = 'tokens_scopes_id'; |
||
62 | |||
63 | /** View name */ |
||
64 | const VIEW_PASSPORT = 'vw_oauth_passport'; |
||
65 | |||
66 | /** |
||
67 | * @var string|null |
||
68 | */ |
||
69 | private $usersTableName; |
||
70 | |||
71 | /** |
||
72 | * @var string|null |
||
73 | */ |
||
74 | private $usersIdColumn; |
||
75 | |||
76 | /** |
||
77 | * @param null|string $usersTableName |
||
78 | * @param null|string $usersIdColumn |
||
79 | */ |
||
80 | 80 | public function __construct(string $usersTableName = null, string $usersIdColumn = null) |
|
85 | |||
86 | /** |
||
87 | * @inheritdoc |
||
88 | */ |
||
89 | 66 | public function getClientsTable(): string |
|
93 | |||
94 | /** |
||
95 | * @inheritdoc |
||
96 | */ |
||
97 | 5 | public function getClientsView(): string |
|
101 | |||
102 | /** |
||
103 | * @inheritdoc |
||
104 | */ |
||
105 | 3 | public function getClientsViewScopesColumn(): string |
|
109 | |||
110 | /** |
||
111 | * @inheritdoc |
||
112 | */ |
||
113 | 3 | public function getClientsViewRedirectUrisColumn(): string |
|
117 | |||
118 | /** |
||
119 | * @inheritdoc |
||
120 | */ |
||
121 | 38 | public function getClientsIdentityColumn(): string |
|
125 | |||
126 | /** |
||
127 | * @inheritdoc |
||
128 | */ |
||
129 | 34 | public function getClientsNameColumn(): string |
|
133 | |||
134 | /** |
||
135 | * @inheritdoc |
||
136 | */ |
||
137 | 34 | public function getClientsDescriptionColumn(): string |
|
141 | |||
142 | /** |
||
143 | * @inheritdoc |
||
144 | */ |
||
145 | 34 | public function getClientsCredentialsColumn(): string |
|
149 | |||
150 | /** |
||
151 | * @inheritdoc |
||
152 | */ |
||
153 | 34 | public function getClientsIsConfidentialColumn(): string |
|
157 | |||
158 | /** |
||
159 | * @inheritdoc |
||
160 | */ |
||
161 | 34 | public function getClientsIsScopeExcessAllowedColumn(): string |
|
165 | |||
166 | /** |
||
167 | * @inheritdoc |
||
168 | */ |
||
169 | 34 | public function getClientsIsUseDefaultScopeColumn(): string |
|
173 | |||
174 | /** |
||
175 | * @inheritdoc |
||
176 | */ |
||
177 | 34 | public function getClientsIsCodeGrantEnabledColumn(): string |
|
181 | |||
182 | /** |
||
183 | * @inheritdoc |
||
184 | */ |
||
185 | 34 | public function getClientsIsImplicitGrantEnabledColumn(): string |
|
189 | |||
190 | /** |
||
191 | * @inheritdoc |
||
192 | */ |
||
193 | 34 | public function getClientsIsPasswordGrantEnabledColumn(): string |
|
197 | |||
198 | /** |
||
199 | * @inheritdoc |
||
200 | */ |
||
201 | 34 | public function getClientsIsClientGrantEnabledColumn(): string |
|
205 | |||
206 | /** |
||
207 | * @inheritdoc |
||
208 | */ |
||
209 | 33 | public function getClientsIsRefreshGrantEnabledColumn(): string |
|
213 | |||
214 | /** |
||
215 | * @inheritdoc |
||
216 | */ |
||
217 | 33 | public function getClientsCreatedAtColumn(): string |
|
221 | |||
222 | /** |
||
223 | * @inheritdoc |
||
224 | */ |
||
225 | 33 | public function getClientsUpdatedAtColumn(): string |
|
229 | |||
230 | /** |
||
231 | * @inheritdoc |
||
232 | */ |
||
233 | 66 | public function getClientsScopesTable(): string |
|
237 | |||
238 | /** |
||
239 | * @inheritdoc |
||
240 | */ |
||
241 | 32 | public function getClientsScopesIdentityColumn(): string |
|
245 | |||
246 | /** |
||
247 | * @inheritdoc |
||
248 | */ |
||
249 | 37 | public function getClientsScopesClientIdentityColumn(): string |
|
253 | |||
254 | /** |
||
255 | * @inheritdoc |
||
256 | */ |
||
257 | 34 | public function getClientsScopesScopeIdentityColumn(): string |
|
261 | |||
262 | /** |
||
263 | * @inheritdoc |
||
264 | */ |
||
265 | 68 | public function getRedirectUrisTable(): string |
|
269 | |||
270 | /** |
||
271 | * @inheritdoc |
||
272 | */ |
||
273 | 35 | public function getRedirectUrisIdentityColumn(): string |
|
277 | |||
278 | /** |
||
279 | * @inheritdoc |
||
280 | */ |
||
281 | 38 | public function getRedirectUrisClientIdentityColumn(): string |
|
285 | |||
286 | /** |
||
287 | * @inheritdoc |
||
288 | */ |
||
289 | 37 | public function getRedirectUrisValueColumn(): string |
|
293 | |||
294 | /** |
||
295 | * @inheritdoc |
||
296 | */ |
||
297 | 33 | public function getRedirectUrisCreatedAtColumn(): string |
|
301 | |||
302 | /** |
||
303 | * @inheritdoc |
||
304 | */ |
||
305 | 33 | public function getRedirectUrisUpdatedAtColumn(): string |
|
309 | |||
310 | /** |
||
311 | * @inheritdoc |
||
312 | */ |
||
313 | 66 | public function getScopesTable(): string |
|
317 | |||
318 | /** |
||
319 | * @inheritdoc |
||
320 | */ |
||
321 | 39 | public function getScopesIdentityColumn(): string |
|
325 | |||
326 | /** |
||
327 | * @inheritdoc |
||
328 | */ |
||
329 | 35 | public function getScopesDescriptionColumn(): string |
|
333 | |||
334 | /** |
||
335 | * @inheritdoc |
||
336 | */ |
||
337 | 34 | public function getScopesCreatedAtColumn(): string |
|
341 | |||
342 | /** |
||
343 | * @inheritdoc |
||
344 | */ |
||
345 | 34 | public function getScopesUpdatedAtColumn(): string |
|
349 | |||
350 | /** |
||
351 | * @inheritdoc |
||
352 | */ |
||
353 | 66 | public function getTokensTable(): string |
|
357 | |||
358 | /** |
||
359 | * @inheritdoc |
||
360 | */ |
||
361 | 7 | public function getTokensView(): string |
|
365 | |||
366 | /** |
||
367 | * @inheritdoc |
||
368 | */ |
||
369 | 6 | public function getTokensViewScopesColumn(): string |
|
373 | |||
374 | /** |
||
375 | * @inheritdoc |
||
376 | */ |
||
377 | 38 | public function getTokensIdentityColumn(): string |
|
381 | |||
382 | /** |
||
383 | * @inheritdoc |
||
384 | */ |
||
385 | 42 | public function getTokensIsEnabledColumn(): string |
|
389 | |||
390 | /** |
||
391 | * @inheritdoc |
||
392 | */ |
||
393 | 34 | public function getTokensIsScopeModified(): string |
|
397 | |||
398 | /** |
||
399 | * @inheritdoc |
||
400 | */ |
||
401 | 35 | public function getTokensClientIdentityColumn(): string |
|
405 | |||
406 | /** |
||
407 | * @inheritdoc |
||
408 | */ |
||
409 | 39 | public function getTokensUserIdentityColumn(): string |
|
413 | |||
414 | /** |
||
415 | * @inheritdoc |
||
416 | */ |
||
417 | 32 | public function getTokensRedirectUriColumn(): string |
|
421 | |||
422 | /** |
||
423 | * @inheritdoc |
||
424 | */ |
||
425 | 35 | public function getTokensCodeColumn(): string |
|
429 | |||
430 | /** |
||
431 | * @inheritdoc |
||
432 | */ |
||
433 | 42 | public function getTokensValueColumn(): string |
|
437 | |||
438 | /** |
||
439 | * @inheritdoc |
||
440 | */ |
||
441 | 34 | public function getTokensTypeColumn(): string |
|
445 | |||
446 | /** |
||
447 | * @inheritdoc |
||
448 | */ |
||
449 | 32 | public function getTokensRefreshColumn(): string |
|
453 | |||
454 | /** |
||
455 | * @inheritdoc |
||
456 | */ |
||
457 | 35 | public function getTokensCodeCreatedAtColumn(): string |
|
461 | |||
462 | /** |
||
463 | * @inheritdoc |
||
464 | */ |
||
465 | 43 | public function getTokensValueCreatedAtColumn(): string |
|
469 | |||
470 | /** |
||
471 | * @inheritdoc |
||
472 | */ |
||
473 | 32 | public function getTokensRefreshCreatedAtColumn(): string |
|
477 | |||
478 | /** |
||
479 | * @inheritdoc |
||
480 | */ |
||
481 | 66 | public function getTokensScopesTable(): string |
|
485 | |||
486 | /** |
||
487 | * @inheritdoc |
||
488 | */ |
||
489 | 32 | public function getTokensScopesIdentityColumn(): string |
|
493 | |||
494 | /** |
||
495 | * @inheritdoc |
||
496 | */ |
||
497 | 37 | public function getTokensScopesTokenIdentityColumn(): string |
|
501 | |||
502 | /** |
||
503 | * @inheritdoc |
||
504 | */ |
||
505 | 36 | public function getTokensScopesScopeIdentityColumn(): string |
|
509 | |||
510 | /** |
||
511 | * @inheritdoc |
||
512 | */ |
||
513 | 5 | public function getUsersView(): ?string |
|
517 | |||
518 | /** |
||
519 | * @inheritdoc |
||
520 | */ |
||
521 | 35 | public function getUsersTable(): ?string |
|
525 | |||
526 | /** |
||
527 | * @inheritdoc |
||
528 | */ |
||
529 | 35 | public function getUsersIdentityColumn(): ?string |
|
533 | |||
534 | /** |
||
535 | * @inheritdoc |
||
536 | */ |
||
537 | 9 | public function getPassportView(): ?string |
|
541 | } |
||
542 |