Passed
Push — main ( 72c6fa...9344f0 )
by Sílvio
02:59
created

RedisCacheManager::auth()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 2
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Silviooosilva\CacheerPhp\CacheStore\CacheManager;
4
5
use Predis\Client;
6
use Predis\Autoloader;
7
8
class RedisCacheManager 
9
{
10
11
  /** @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...
12
  private static $redis;
13
14
  /** @param string $namespace */
15
  private static $namespace;
16
17
  /**
18
  * @return Client
19
  */
20
  public static function connect()
21
  {
22
    Autoloader::register();
23
    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...
24
      'scheme' => 'tcp',
25
      'host' => REDIS_CONNECTION_CONFIG['REDIS_HOST'],
26
      'port' => REDIS_CONNECTION_CONFIG['REDIS_PORT'],
27
      'password' => REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'],
28
      'database' => 0
29
    ]);
30
    self::auth();
31
    self::$namespace = REDIS_CONNECTION_CONFIG['REDIS_NAMESPACE'] ?? 'Cache';
32
    return self::$redis;
33
  }
34
35
  /**
36
  * @return void
37
  */
38
  private static function auth()
39
  {
40
    if(is_string(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']) && REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'] !== '') {
41
      self::$redis->auth(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']);
42
    }
43
  }
44
45
}