RedisCacheManager   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A auth() 0 4 3
A connect() 0 13 1
1
<?php
2
3
namespace Silviooosilva\CacheerPhp\CacheStore\CacheManager;
4
5
use Predis\Client;
6
use Predis\Autoloader;
7
8
9
/**
10
 * Class RedisCacheManager
11
 * @author Sílvio Silva <https://github.com/silviooosilva>
12
 * @package Silviooosilva\CacheerPhp
13
 */
14
class RedisCacheManager
15
{
16
17
  /** @var Predis\Client */
0 ignored issues
show
Bug introduced by
The type Silviooosilva\CacheerPhp...heManager\Predis\Client was not found. Did you mean Predis\Client? If so, make sure to prefix the type with \.
Loading history...
18
  private static $redis;
19
20
  /** @param string $namespace */
21
  private static $namespace;
22
23
  /**
24
  * @return Client
25
  */
26
  public static function connect()
27
  {
28
    Autoloader::register();
29
    self::$redis = new Client([
0 ignored issues
show
Documentation Bug introduced by
It seems like new Predis\Client(array(...RD'], 'database' => 0)) of type Predis\Client is incompatible with the declared type Silviooosilva\CacheerPhp...heManager\Predis\Client of property $redis.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
30
      'scheme' => 'tcp',
31
      'host' => REDIS_CONNECTION_CONFIG['REDIS_HOST'],
32
      'port' => REDIS_CONNECTION_CONFIG['REDIS_PORT'],
33
      'password' => REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'],
34
      'database' => 0
35
    ]);
36
    self::auth();
37
    self::$namespace = REDIS_CONNECTION_CONFIG['REDIS_NAMESPACE'] ?? 'Cache';
38
    return self::$redis;
39
  }
40
41
  /**
42
  * @return void
43
  */
44
  private static function auth()
45
  {
46
    if(is_string(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']) && REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'] !== '') {
47
      self::$redis->auth(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']);
48
    }
49
  }
50
51
}
52