Completed
Push — master ( ea3a48...b57255 )
by Lars
02:48
created

AdapterPredis::removeAll()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 2
eloc 5
nc 2
nop 0
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 $client
26
   */
27
  public function __construct($client)
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->installed = true;
31
      $this->client = $client;
32
    }
33
  }
34
35
  /**
36
   * get
37
   *
38
   * @param $key
39
   *
40
   * @return string
41
   */
42
  public function get($key)
43
  {
44
    return $this->client->get($key);
45
  }
46
47
  /**
48
   * set
49
   *
50
   * @param $key
51
   * @param $value
52
   *
53
   * @return mixed
54
   */
55
  public function set($key, $value)
56
  {
57
    return $this->client->set($key, $value);
58
  }
59
60
  /**
61
   * set expired
62
   *
63
   * @param $key
64
   * @param $value
65
   * @param $ttl
66
   *
67
   * @return int
68
   */
69
  public function setExpired($key, $value, $ttl)
70
  {
71
    return $this->client->setex($key, $ttl, $value);
72
  }
73
74
  /**
75
   * remove
76
   *
77
   * @param $key
78
   *
79
   * @return int
80
   */
81
  public function remove($key)
82
  {
83
    return $this->client->del($key);
84
  }
85
86
  /**
87
   * remove all
88
   *
89
   * @return bool
90
   */
91
  public function removeAll()
92
  {
93
    $return = array();
94
    foreach ($this->client->keys('*') as $key) {
95
      $return[] = $this->remove($key);
96
    }
97
98
    return !in_array(false, $return);
99
  }
100
101
  /**
102
   * check if cache is installed
103
   *
104
   * @return boolean
105
   */
106
  public function installed()
107
  {
108
    return $this->installed;
109
  }
110
111
112
  /**
113
   * @param $key
114
   *
115
   * @return int
116
   */
117
  public function exists($key)
118
  {
119
    return $this->client->exists($key);
120
  }
121
}
122