Pdo   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 79.17%

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 46
ccs 19
cts 24
cp 0.7917
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 36 6
1
<?php
2
3
namespace roaresearch\yii2\oauth2server\storage;
4
5
class Pdo extends \OAuth2\Storage\Pdo
6
{
7
    public $dsn;
8
    
9
    public $username;
10
    
11
    public $password;
12
    
13
    public $connection = 'db';
14
    
15 9
    public function __construct($connection = null, $config = array())
16
    {
17 9
        if($connection === null) {
18 9
            if($this->connection !== null && \Yii::$app->has($this->connection)) {
19 9
                $db = \Yii::$app->get($this->connection);
20 9
                if(!($db instanceof \yii\db\Connection)) {
21
                    throw new \yii\base\InvalidConfigException('Connection component must implement \yii\db\Connection.');
22
                }
23
                
24 9
                if(!$db->getIsActive()) {
25 5
                    $db->open();
26
                }
27
                
28 9
                $connection = $db->pdo;
29 9
                $config = array_merge(array(
30 9
                    'client_table' => $db->tablePrefix . 'oauth_clients',
31 9
                    'access_token_table' => $db->tablePrefix . 'oauth_access_tokens',
32 9
                    'refresh_token_table' => $db->tablePrefix . 'oauth_refresh_tokens',
33 9
                    'code_table' => $db->tablePrefix . 'oauth_authorization_codes',
34 9
                    'user_table' => $db->tablePrefix . 'oauth_users',
35 9
                    'jwt_table'  => $db->tablePrefix . 'oauth_jwt',
36 9
                    'jti_table'  => $db->tablePrefix . 'oauth_jti',
37 9
                    'scope_table'  => $db->tablePrefix . 'oauth_scopes',
38 9
                    'public_key_table'  => $db->tablePrefix . 'oauth_public_keys',
39
                ), $config);
40
                
41
            } else {
42
                $connection = [
43
                    'dsn' => $this->dsn,
44
                    'username' => $this->username,
45
                    'password' => $this->password
46
                ];
47
            }
48
        }
49
        
50 9
        parent::__construct($connection, $config);
51
    }
52
}
53