Complex classes like DatabaseScheme 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 DatabaseScheme, and based on these observations, apply Extract Interface, too.
1 | <?php namespace Limoncello\Passport\Entities; |
||
26 | class DatabaseScheme implements DatabaseSchemeInterface |
||
27 | { |
||
28 | /** Table name */ |
||
29 | const TABLE_CLIENTS = 'oauth_clients'; |
||
30 | |||
31 | /** View name */ |
||
32 | const VIEW_CLIENTS = 'vw_oauth_clients'; |
||
33 | |||
34 | /** Table name */ |
||
35 | const TABLE_CLIENTS_SCOPES = 'oauth_clients_scopes'; |
||
36 | |||
37 | /** Table name */ |
||
38 | const TABLE_REDIRECT_URIS = 'oauth_redirect_uris'; |
||
39 | |||
40 | /** Table name */ |
||
41 | const TABLE_SCOPES = 'oauth_scopes'; |
||
42 | |||
43 | /** Table name */ |
||
44 | const TABLE_TOKENS = 'oauth_tokens'; |
||
45 | |||
46 | /** View name */ |
||
47 | const VIEW_TOKENS = 'vw_oauth_tokens'; |
||
48 | |||
49 | /** Table name */ |
||
50 | const TABLE_TOKENS_SCOPES = 'oauth_tokens_scopes'; |
||
51 | |||
52 | /** View name */ |
||
53 | const VIEW_USERS = 'vw_oauth_users'; |
||
54 | |||
55 | /** Field name */ |
||
56 | const CLIENTS_SCOPES_FIELD_ID = 'clients_scopes_id'; |
||
57 | |||
58 | /** Field name */ |
||
59 | const TOKENS_SCOPES_FIELD_ID = 'tokens_scopes_id'; |
||
60 | |||
61 | /** View name */ |
||
62 | const VIEW_PASSPORT = 'vw_oauth_passport'; |
||
63 | |||
64 | /** |
||
65 | * @var string|null |
||
66 | */ |
||
67 | private $usersTableName; |
||
68 | |||
69 | /** |
||
70 | * @var string|null |
||
71 | */ |
||
72 | private $usersIdColumn; |
||
73 | |||
74 | /** |
||
75 | * @param null|string $usersTableName |
||
76 | * @param null|string $usersIdColumn |
||
77 | */ |
||
78 | public function __construct(string $usersTableName = null, string $usersIdColumn = null) |
||
83 | |||
84 | /** |
||
85 | * @inheritdoc |
||
86 | */ |
||
87 | public function getClientsTable(): string |
||
91 | |||
92 | /** |
||
93 | * @inheritdoc |
||
94 | */ |
||
95 | public function getClientsView(): string |
||
99 | |||
100 | /** |
||
101 | * @inheritdoc |
||
102 | */ |
||
103 | public function getClientsViewScopesColumn(): string |
||
107 | |||
108 | /** |
||
109 | * @inheritdoc |
||
110 | */ |
||
111 | public function getClientsViewRedirectUrisColumn(): string |
||
115 | |||
116 | /** |
||
117 | * @inheritdoc |
||
118 | */ |
||
119 | public function getClientsIdentityColumn(): string |
||
123 | |||
124 | /** |
||
125 | * @inheritdoc |
||
126 | */ |
||
127 | public function getClientsNameColumn(): string |
||
131 | |||
132 | /** |
||
133 | * @inheritdoc |
||
134 | */ |
||
135 | public function getClientsDescriptionColumn(): string |
||
139 | |||
140 | /** |
||
141 | * @inheritdoc |
||
142 | */ |
||
143 | public function getClientsCredentialsColumn(): string |
||
147 | |||
148 | /** |
||
149 | * @inheritdoc |
||
150 | */ |
||
151 | public function getClientsIsConfidentialColumn(): string |
||
155 | |||
156 | /** |
||
157 | * @inheritdoc |
||
158 | */ |
||
159 | public function getClientsIsScopeExcessAllowedColumn(): string |
||
163 | |||
164 | /** |
||
165 | * @inheritdoc |
||
166 | */ |
||
167 | public function getClientsIsUseDefaultScopeColumn(): string |
||
171 | |||
172 | /** |
||
173 | * @inheritdoc |
||
174 | */ |
||
175 | public function getClientsIsCodeGrantEnabledColumn(): string |
||
179 | |||
180 | /** |
||
181 | * @inheritdoc |
||
182 | */ |
||
183 | public function getClientsIsImplicitGrantEnabledColumn(): string |
||
187 | |||
188 | /** |
||
189 | * @inheritdoc |
||
190 | */ |
||
191 | public function getClientsIsPasswordGrantEnabledColumn(): string |
||
195 | |||
196 | /** |
||
197 | * @inheritdoc |
||
198 | */ |
||
199 | public function getClientsIsClientGrantEnabledColumn(): string |
||
203 | |||
204 | /** |
||
205 | * @inheritdoc |
||
206 | */ |
||
207 | public function getClientsIsRefreshGrantEnabledColumn(): string |
||
211 | |||
212 | /** |
||
213 | * @inheritdoc |
||
214 | */ |
||
215 | public function getClientsCreatedAtColumn(): string |
||
219 | |||
220 | /** |
||
221 | * @inheritdoc |
||
222 | */ |
||
223 | public function getClientsUpdatedAtColumn(): string |
||
227 | |||
228 | /** |
||
229 | * @inheritdoc |
||
230 | */ |
||
231 | public function getClientsScopesTable(): string |
||
235 | |||
236 | /** |
||
237 | * @inheritdoc |
||
238 | */ |
||
239 | public function getClientsScopesIdentityColumn(): string |
||
243 | |||
244 | /** |
||
245 | * @inheritdoc |
||
246 | */ |
||
247 | public function getClientsScopesClientIdentityColumn(): string |
||
251 | |||
252 | /** |
||
253 | * @inheritdoc |
||
254 | */ |
||
255 | public function getClientsScopesScopeIdentityColumn(): string |
||
259 | |||
260 | /** |
||
261 | * @inheritdoc |
||
262 | */ |
||
263 | public function getRedirectUrisTable(): string |
||
267 | |||
268 | /** |
||
269 | * @inheritdoc |
||
270 | */ |
||
271 | public function getRedirectUrisIdentityColumn(): string |
||
275 | |||
276 | /** |
||
277 | * @inheritdoc |
||
278 | */ |
||
279 | public function getRedirectUrisClientIdentityColumn(): string |
||
283 | |||
284 | /** |
||
285 | * @inheritdoc |
||
286 | */ |
||
287 | public function getRedirectUrisValueColumn(): string |
||
291 | |||
292 | /** |
||
293 | * @inheritdoc |
||
294 | */ |
||
295 | public function getRedirectUrisCreatedAtColumn(): string |
||
299 | |||
300 | /** |
||
301 | * @inheritdoc |
||
302 | */ |
||
303 | public function getRedirectUrisUpdatedAtColumn(): string |
||
307 | |||
308 | /** |
||
309 | * @inheritdoc |
||
310 | */ |
||
311 | public function getScopesTable(): string |
||
315 | |||
316 | /** |
||
317 | * @inheritdoc |
||
318 | */ |
||
319 | public function getScopesIdentityColumn(): string |
||
323 | |||
324 | /** |
||
325 | * @inheritdoc |
||
326 | */ |
||
327 | public function getScopesDescriptionColumn(): string |
||
331 | |||
332 | /** |
||
333 | * @inheritdoc |
||
334 | */ |
||
335 | public function getScopesCreatedAtColumn(): string |
||
339 | |||
340 | /** |
||
341 | * @inheritdoc |
||
342 | */ |
||
343 | public function getScopesUpdatedAtColumn(): string |
||
347 | |||
348 | /** |
||
349 | * @inheritdoc |
||
350 | */ |
||
351 | public function getTokensTable(): string |
||
355 | |||
356 | /** |
||
357 | * @inheritdoc |
||
358 | */ |
||
359 | public function getTokensView(): string |
||
363 | |||
364 | /** |
||
365 | * @inheritdoc |
||
366 | */ |
||
367 | public function getTokensViewScopesColumn(): string |
||
371 | |||
372 | /** |
||
373 | * @inheritdoc |
||
374 | */ |
||
375 | public function getTokensIdentityColumn(): string |
||
379 | |||
380 | /** |
||
381 | * @inheritdoc |
||
382 | */ |
||
383 | public function getTokensIsEnabledColumn(): string |
||
387 | |||
388 | /** |
||
389 | * @inheritdoc |
||
390 | */ |
||
391 | public function getTokensIsScopeModified(): string |
||
395 | |||
396 | /** |
||
397 | * @inheritdoc |
||
398 | */ |
||
399 | public function getTokensClientIdentityColumn(): string |
||
403 | |||
404 | /** |
||
405 | * @inheritdoc |
||
406 | */ |
||
407 | public function getTokensUserIdentityColumn(): string |
||
411 | |||
412 | /** |
||
413 | * @inheritdoc |
||
414 | */ |
||
415 | public function getTokensRedirectUriColumn(): string |
||
419 | |||
420 | /** |
||
421 | * @inheritdoc |
||
422 | */ |
||
423 | public function getTokensCodeColumn(): string |
||
427 | |||
428 | /** |
||
429 | * @inheritdoc |
||
430 | */ |
||
431 | public function getTokensValueColumn(): string |
||
435 | |||
436 | /** |
||
437 | * @inheritdoc |
||
438 | */ |
||
439 | public function getTokensTypeColumn(): string |
||
443 | |||
444 | /** |
||
445 | * @inheritdoc |
||
446 | */ |
||
447 | public function getTokensRefreshColumn(): string |
||
451 | |||
452 | /** |
||
453 | * @inheritdoc |
||
454 | */ |
||
455 | public function getTokensCodeCreatedAtColumn(): string |
||
459 | |||
460 | /** |
||
461 | * @inheritdoc |
||
462 | */ |
||
463 | public function getTokensValueCreatedAtColumn(): string |
||
467 | |||
468 | /** |
||
469 | * @inheritdoc |
||
470 | */ |
||
471 | public function getTokensRefreshCreatedAtColumn(): string |
||
475 | |||
476 | /** |
||
477 | * @inheritdoc |
||
478 | */ |
||
479 | public function getTokensScopesTable(): string |
||
483 | |||
484 | /** |
||
485 | * @inheritdoc |
||
486 | */ |
||
487 | public function getTokensScopesIdentityColumn(): string |
||
491 | |||
492 | /** |
||
493 | * @inheritdoc |
||
494 | */ |
||
495 | public function getTokensScopesTokenIdentityColumn(): string |
||
499 | |||
500 | /** |
||
501 | * @inheritdoc |
||
502 | */ |
||
503 | public function getTokensScopesScopeIdentityColumn(): string |
||
507 | |||
508 | /** |
||
509 | * @inheritdoc |
||
510 | */ |
||
511 | public function getUsersView() |
||
515 | |||
516 | /** |
||
517 | * @inheritdoc |
||
518 | */ |
||
519 | public function getUsersTable() |
||
523 | |||
524 | /** |
||
525 | * @inheritdoc |
||
526 | */ |
||
527 | public function getUsersIdentityColumn() |
||
531 | |||
532 | /** |
||
533 | * @inheritdoc |
||
534 | */ |
||
535 | public function getPassportView() |
||
539 | } |
||
540 |