Predis   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 1
dl 0
loc 43
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 7 2
A getClient() 0 8 2
A getParams() 0 13 3
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: zjw
5
 * Date: 2017/8/25
6
 * Time: 下午3:45
7
 */
8
9
namespace zacksleo\yii2\oauth2\common\helpers;
10
11
use monsterhunter\oauth2\redis\RedisClient;
12
13
class Predis
14
{
15
    private static $instance;
16
17
    private static $clientSet;
18
19
    /**
20
     * @return Predis
21
     */
22 3
    public static function getInstance()
23
    {
24 3
        if (!isset(self::$instance)) {
25 1
            self::$instance = new self();
26
        }
27 3
        return self::$instance;
28
    }
29
30
    /**
31
     * @return \monsterhunter\oauth2\redis\RedisClient
32
     */
33 3
    public function getClient()
34
    {
35 3
        if (!isset(self::$clientSet['PredisClient'])) {
36 1
            $client = new RedisClient($this->getParams());
37 1
            self::$clientSet['PredisClient'] = $client;
38
        }
39 3
        return self::$clientSet['PredisClient'];
40
    }
41
42 1
    private function getParams()
43
    {
44
        $params = [
45 1
            'host' => getenv('TOKEN_REDIS_HOST'),
46 1
            'port' => getenv('TOKEN_REDIS_PORT'),
47 1
            'database' => getenv('TOKEN_REDIS_DATABASE'),
48 1
            'password' => getenv('TOKEN_REDIS_PASSWORD')
49
        ];
50 1
        if ($params['password'] == 'null' || empty($params['password'])) {
51 1
            unset($params['password']);
52
        }
53 1
        return $params;
54
    }
55
}
56