Completed
Push — master ( 6a7f55...29301f )
by Lars
02:40
created

AdapterPredis::setPredisClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace voku\cache;
4
5
use Predis\Client;
6
7
/**
8
 * AdapterPredis: Memcached-adapter
9
 *
10
 * @package   voku\cache
11
 */
12
class AdapterPredis implements iAdapter
13
{
14
  /**
15
   * @var bool
16
   */
17
  public $installed = false;
18
19
  /**
20
   * @var Client
21
   */
22
  private $client;
23
24
  /**
25
   * @param Client|null $client
26
   */
27
  public function __construct($client = null)
28
  {
29
    if ($client instanceof Client) {
0 ignored issues
show
Bug introduced by
The class Predis\Client does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
30
      $this->setPredisClient($client);
31
    }
32
  }
33
34
  /**
35
   * @param Client $client
36
   */
37
  public function setPredisClient(Client $client)
38
  {
39
    $this->installed = true;
40
    $this->client = $client;
41
  }
42
43
44
  /**
45
   * @inheritdoc
46
   */
47
  public function exists($key)
48
  {
49
    return $this->client->exists($key);
50
  }
51
52
  /**
53
   * @inheritdoc
54
   */
55
  public function get($key)
56
  {
57
    return $this->client->get($key);
58
  }
59
60
  /**
61
   * @inheritdoc
62
   */
63
  public function installed()
64
  {
65
    return $this->installed;
66
  }
67
68
  /**
69
   * @inheritdoc
70
   */
71
  public function remove($key)
72
  {
73
    return $this->client->del($key);
74
  }
75
76
  /**
77
   * @inheritdoc
78
   */
79
  public function removeAll()
80
  {
81
    return $this->client->flushall();
82
  }
83
84
  /**
85
   * @inheritdoc
86
   */
87
  public function set($key, $value)
88
  {
89
    return $this->client->set($key, $value);
90
  }
91
92
  /**
93
   * @inheritdoc
94
   */
95
  public function setExpired($key, $value, $ttl)
96
  {
97
    return $this->client->setex($key, $ttl, $value);
98
  }
99
}
100