RedisCacheManager   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 38
rs 10
c 1
b 0
f 0
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
   * Connects to the Redis server using the configuration defined in REDIS_CONNECTION_CONFIG.
25
   * 
26
  * @return Client
27
  */
28
  public static function connect()
29
  {
30
    Autoloader::register();
31
    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...
32
      'scheme' => 'tcp',
33
      'host' => REDIS_CONNECTION_CONFIG['REDIS_HOST'],
34
      'port' => REDIS_CONNECTION_CONFIG['REDIS_PORT'],
35
      'password' => REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'],
36
      'database' => 0
37
    ]);
38
    self::auth();
39
    self::$namespace = REDIS_CONNECTION_CONFIG['REDIS_NAMESPACE'] ?? 'Cache';
40
    return self::$redis;
41
  }
42
43
  /**
44
  * Authenticates the Redis connection if a password is provided in the configuration.
45
  *
46
  * @return void
47
  */
48
  private static function auth(): void
49
  {
50
    if(is_string(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']) && REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'] !== '') {
51
      self::$redis->auth(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']);
52
    }
53
  }
54
55
}
56