Completed
Push — master ( 9a9433...7c3a00 )
by Neomerx
03:35
created

DatabaseScheme   D

Complexity

Total Complexity 58

Size/Duplication

Total Lines 514
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 514
c 0
b 0
f 0
wmc 58
lcom 0
cbo 0
rs 4.8387

58 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getClientsTable() 0 4 1
A getClientsView() 0 4 1
A getClientsViewScopesColumn() 0 4 1
A getClientsViewRedirectUrisColumn() 0 4 1
A getClientsIdentityColumn() 0 4 1
A getClientsNameColumn() 0 4 1
A getClientsDescriptionColumn() 0 4 1
A getClientsCredentialsColumn() 0 4 1
A getClientsIsConfidentialColumn() 0 4 1
A getClientsIsScopeExcessAllowedColumn() 0 4 1
A getClientsIsUseDefaultScopeColumn() 0 4 1
A getClientsIsCodeGrantEnabledColumn() 0 4 1
A getClientsIsImplicitGrantEnabledColumn() 0 4 1
A getClientsIsPasswordGrantEnabledColumn() 0 4 1
A getClientsIsClientGrantEnabledColumn() 0 4 1
A getClientsIsRefreshGrantEnabledColumn() 0 4 1
A getClientsCreatedAtColumn() 0 4 1
A getClientsUpdatedAtColumn() 0 4 1
A getClientsScopesTable() 0 4 1
A getClientsScopesIdentityColumn() 0 4 1
A getClientsScopesClientIdentityColumn() 0 4 1
A getClientsScopesScopeIdentityColumn() 0 4 1
A getRedirectUrisTable() 0 4 1
A getRedirectUrisIdentityColumn() 0 4 1
A getRedirectUrisClientIdentityColumn() 0 4 1
A getRedirectUrisValueColumn() 0 4 1
A getRedirectUrisCreatedAtColumn() 0 4 1
A getRedirectUrisUpdatedAtColumn() 0 4 1
A getScopesTable() 0 4 1
A getScopesIdentityColumn() 0 4 1
A getScopesDescriptionColumn() 0 4 1
A getScopesCreatedAtColumn() 0 4 1
A getScopesUpdatedAtColumn() 0 4 1
A getTokensTable() 0 4 1
A getTokensView() 0 4 1
A getTokensViewScopesColumn() 0 4 1
A getTokensIdentityColumn() 0 4 1
A getTokensIsEnabledColumn() 0 4 1
A getTokensIsScopeModified() 0 4 1
A getTokensClientIdentityColumn() 0 4 1
A getTokensUserIdentityColumn() 0 4 1
A getTokensRedirectUriColumn() 0 4 1
A getTokensCodeColumn() 0 4 1
A getTokensValueColumn() 0 4 1
A getTokensTypeColumn() 0 4 1
A getTokensRefreshColumn() 0 4 1
A getTokensCodeCreatedAtColumn() 0 4 1
A getTokensValueCreatedAtColumn() 0 4 1
A getTokensRefreshCreatedAtColumn() 0 4 1
A getTokensScopesTable() 0 4 1
A getTokensScopesIdentityColumn() 0 4 1
A getTokensScopesTokenIdentityColumn() 0 4 1
A getTokensScopesScopeIdentityColumn() 0 4 1
A getUsersView() 0 4 1
A getUsersTable() 0 4 1
A getUsersIdentityColumn() 0 4 1
A getPassportView() 0 4 1

How to fix   Complexity   

Complex Class

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;
2
3
/**
4
 * Copyright 2015-2017 [email protected]
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use Limoncello\Passport\Contracts\Entities\DatabaseSchemeInterface;
20
21
/**
22
 * @package Limoncello\Passport
23
 *
24
 * @SuppressWarnings(PHPMD)
25
 */
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)
79
    {
80
        $this->usersTableName = $usersTableName;
81
        $this->usersIdColumn  = $usersIdColumn;
82
    }
83
84
    /**
85
     * @inheritdoc
86
     */
87
    public function getClientsTable(): string
88
    {
89
        return static::TABLE_CLIENTS;
90
    }
91
92
    /**
93
     * @inheritdoc
94
     */
95
    public function getClientsView(): string
96
    {
97
        return static::VIEW_CLIENTS;
98
    }
99
100
    /**
101
     * @inheritdoc
102
     */
103
    public function getClientsViewScopesColumn(): string
104
    {
105
        return Client::FIELD_SCOPES;
106
    }
107
108
    /**
109
     * @inheritdoc
110
     */
111
    public function getClientsViewRedirectUrisColumn(): string
112
    {
113
        return Client::FIELD_REDIRECT_URIS;
114
    }
115
116
    /**
117
     * @inheritdoc
118
     */
119
    public function getClientsIdentityColumn(): string
120
    {
121
        return Client::FIELD_ID;
122
    }
123
124
    /**
125
     * @inheritdoc
126
     */
127
    public function getClientsNameColumn(): string
128
    {
129
        return Client::FIELD_NAME;
130
    }
131
132
    /**
133
     * @inheritdoc
134
     */
135
    public function getClientsDescriptionColumn(): string
136
    {
137
        return Client::FIELD_DESCRIPTION;
138
    }
139
140
    /**
141
     * @inheritdoc
142
     */
143
    public function getClientsCredentialsColumn(): string
144
    {
145
        return Client::FIELD_CREDENTIALS;
146
    }
147
148
    /**
149
     * @inheritdoc
150
     */
151
    public function getClientsIsConfidentialColumn(): string
152
    {
153
        return Client::FIELD_IS_CONFIDENTIAL;
154
    }
155
156
    /**
157
     * @inheritdoc
158
     */
159
    public function getClientsIsScopeExcessAllowedColumn(): string
160
    {
161
        return Client::FIELD_IS_SCOPE_EXCESS_ALLOWED;
162
    }
163
164
    /**
165
     * @inheritdoc
166
     */
167
    public function getClientsIsUseDefaultScopeColumn(): string
168
    {
169
        return Client::FIELD_IS_USE_DEFAULT_SCOPE;
170
    }
171
172
    /**
173
     * @inheritdoc
174
     */
175
    public function getClientsIsCodeGrantEnabledColumn(): string
176
    {
177
        return Client::FIELD_IS_CODE_GRANT_ENABLED;
178
    }
179
180
    /**
181
     * @inheritdoc
182
     */
183
    public function getClientsIsImplicitGrantEnabledColumn(): string
184
    {
185
        return Client::FIELD_IS_IMPLICIT_GRANT_ENABLED;
186
    }
187
188
    /**
189
     * @inheritdoc
190
     */
191
    public function getClientsIsPasswordGrantEnabledColumn(): string
192
    {
193
        return Client::FIELD_IS_PASSWORD_GRANT_ENABLED;
194
    }
195
196
    /**
197
     * @inheritdoc
198
     */
199
    public function getClientsIsClientGrantEnabledColumn(): string
200
    {
201
        return Client::FIELD_IS_CLIENT_GRANT_ENABLED;
202
    }
203
204
    /**
205
     * @inheritdoc
206
     */
207
    public function getClientsIsRefreshGrantEnabledColumn(): string
208
    {
209
        return Client::FIELD_IS_REFRESH_GRANT_ENABLED;
210
    }
211
212
    /**
213
     * @inheritdoc
214
     */
215
    public function getClientsCreatedAtColumn(): string
216
    {
217
        return Client::FIELD_CREATED_AT;
218
    }
219
220
    /**
221
     * @inheritdoc
222
     */
223
    public function getClientsUpdatedAtColumn(): string
224
    {
225
        return Client::FIELD_UPDATED_AT;
226
    }
227
228
    /**
229
     * @inheritdoc
230
     */
231
    public function getClientsScopesTable(): string
232
    {
233
        return static::TABLE_CLIENTS_SCOPES;
234
    }
235
236
    /**
237
     * @inheritdoc
238
     */
239
    public function getClientsScopesIdentityColumn(): string
240
    {
241
        return static::CLIENTS_SCOPES_FIELD_ID;
242
    }
243
244
    /**
245
     * @inheritdoc
246
     */
247
    public function getClientsScopesClientIdentityColumn(): string
248
    {
249
        return Client::FIELD_ID;
250
    }
251
252
    /**
253
     * @inheritdoc
254
     */
255
    public function getClientsScopesScopeIdentityColumn(): string
256
    {
257
        return Scope::FIELD_ID;
258
    }
259
260
    /**
261
     * @inheritdoc
262
     */
263
    public function getRedirectUrisTable(): string
264
    {
265
        return static::TABLE_REDIRECT_URIS;
266
    }
267
268
    /**
269
     * @inheritdoc
270
     */
271
    public function getRedirectUrisIdentityColumn(): string
272
    {
273
        return RedirectUri::FIELD_ID;
274
    }
275
276
    /**
277
     * @inheritdoc
278
     */
279
    public function getRedirectUrisClientIdentityColumn(): string
280
    {
281
        return RedirectUri::FIELD_ID_CLIENT;
282
    }
283
284
    /**
285
     * @inheritdoc
286
     */
287
    public function getRedirectUrisValueColumn(): string
288
    {
289
        return RedirectUri::FIELD_VALUE;
290
    }
291
292
    /**
293
     * @inheritdoc
294
     */
295
    public function getRedirectUrisCreatedAtColumn(): string
296
    {
297
        return RedirectUri::FIELD_CREATED_AT;
298
    }
299
300
    /**
301
     * @inheritdoc
302
     */
303
    public function getRedirectUrisUpdatedAtColumn(): string
304
    {
305
        return RedirectUri::FIELD_UPDATED_AT;
306
    }
307
308
    /**
309
     * @inheritdoc
310
     */
311
    public function getScopesTable(): string
312
    {
313
        return static::TABLE_SCOPES;
314
    }
315
316
    /**
317
     * @inheritdoc
318
     */
319
    public function getScopesIdentityColumn(): string
320
    {
321
        return Scope::FIELD_ID;
322
    }
323
324
    /**
325
     * @inheritdoc
326
     */
327
    public function getScopesDescriptionColumn(): string
328
    {
329
        return Scope::FIELD_DESCRIPTION;
330
    }
331
332
    /**
333
     * @inheritdoc
334
     */
335
    public function getScopesCreatedAtColumn(): string
336
    {
337
        return Scope::FIELD_CREATED_AT;
338
    }
339
340
    /**
341
     * @inheritdoc
342
     */
343
    public function getScopesUpdatedAtColumn(): string
344
    {
345
        return Scope::FIELD_UPDATED_AT;
346
    }
347
348
    /**
349
     * @inheritdoc
350
     */
351
    public function getTokensTable(): string
352
    {
353
        return static::TABLE_TOKENS;
354
    }
355
356
    /**
357
     * @inheritdoc
358
     */
359
    public function getTokensView(): string
360
    {
361
        return static::VIEW_TOKENS;
362
    }
363
364
    /**
365
     * @inheritdoc
366
     */
367
    public function getTokensViewScopesColumn(): string
368
    {
369
        return Token::FIELD_SCOPES;
370
    }
371
372
    /**
373
     * @inheritdoc
374
     */
375
    public function getTokensIdentityColumn(): string
376
    {
377
        return Token::FIELD_ID;
378
    }
379
380
    /**
381
     * @inheritdoc
382
     */
383
    public function getTokensIsEnabledColumn(): string
384
    {
385
        return Token::FIELD_IS_ENABLED;
386
    }
387
388
    /**
389
     * @inheritdoc
390
     */
391
    public function getTokensIsScopeModified(): string
392
    {
393
        return Token::FIELD_IS_SCOPE_MODIFIED;
394
    }
395
396
    /**
397
     * @inheritdoc
398
     */
399
    public function getTokensClientIdentityColumn(): string
400
    {
401
        return Token::FIELD_ID_CLIENT;
402
    }
403
404
    /**
405
     * @inheritdoc
406
     */
407
    public function getTokensUserIdentityColumn(): string
408
    {
409
        return Token::FIELD_ID_USER;
410
    }
411
412
    /**
413
     * @inheritdoc
414
     */
415
    public function getTokensRedirectUriColumn(): string
416
    {
417
        return Token::FIELD_REDIRECT_URI;
418
    }
419
420
    /**
421
     * @inheritdoc
422
     */
423
    public function getTokensCodeColumn(): string
424
    {
425
        return Token::FIELD_CODE;
426
    }
427
428
    /**
429
     * @inheritdoc
430
     */
431
    public function getTokensValueColumn(): string
432
    {
433
        return Token::FIELD_VALUE;
434
    }
435
436
    /**
437
     * @inheritdoc
438
     */
439
    public function getTokensTypeColumn(): string
440
    {
441
        return Token::FIELD_TYPE;
442
    }
443
444
    /**
445
     * @inheritdoc
446
     */
447
    public function getTokensRefreshColumn(): string
448
    {
449
        return Token::FIELD_REFRESH;
450
    }
451
452
    /**
453
     * @inheritdoc
454
     */
455
    public function getTokensCodeCreatedAtColumn(): string
456
    {
457
        return Token::FIELD_CODE_CREATED_AT;
458
    }
459
460
    /**
461
     * @inheritdoc
462
     */
463
    public function getTokensValueCreatedAtColumn(): string
464
    {
465
        return Token::FIELD_VALUE_CREATED_AT;
466
    }
467
468
    /**
469
     * @inheritdoc
470
     */
471
    public function getTokensRefreshCreatedAtColumn(): string
472
    {
473
        return Token::FIELD_REFRESH_CREATED_AT;
474
    }
475
476
    /**
477
     * @inheritdoc
478
     */
479
    public function getTokensScopesTable(): string
480
    {
481
        return static::TABLE_TOKENS_SCOPES;
482
    }
483
484
    /**
485
     * @inheritdoc
486
     */
487
    public function getTokensScopesIdentityColumn(): string
488
    {
489
        return static::TOKENS_SCOPES_FIELD_ID;
490
    }
491
492
    /**
493
     * @inheritdoc
494
     */
495
    public function getTokensScopesTokenIdentityColumn(): string
496
    {
497
        return Token::FIELD_ID;
498
    }
499
500
    /**
501
     * @inheritdoc
502
     */
503
    public function getTokensScopesScopeIdentityColumn(): string
504
    {
505
        return Scope::FIELD_ID;
506
    }
507
508
    /**
509
     * @inheritdoc
510
     */
511
    public function getUsersView()
512
    {
513
        return static::VIEW_USERS;
514
    }
515
516
    /**
517
     * @inheritdoc
518
     */
519
    public function getUsersTable()
520
    {
521
        return $this->usersTableName;
522
    }
523
524
    /**
525
     * @inheritdoc
526
     */
527
    public function getUsersIdentityColumn()
528
    {
529
        return $this->usersIdColumn;
530
    }
531
532
    /**
533
     * @inheritdoc
534
     */
535
    public function getPassportView()
536
    {
537
        return static::VIEW_PASSPORT;
538
    }
539
}
540