Completed
Push — master ( 072b8c...b3fbb6 )
by Lars
02:52
created

Cache::getUsedSerializerClassName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace voku\cache;
4
5
/**
6
 * Cache: global-cache class
7
 *
8
 * can use different cache-adapter:
9
 * - Redis
10
 * - Memcache / Memcached
11
 * - APC / APCu
12
 * - Xcache
13
 * - Array
14
 * - File
15
 *
16
 * @package   voku\cache
17
 */
18
class Cache implements iCache
19
{
20
21
  /**
22
   * @var iAdapter
23
   */
24
  private $adapter;
25
26
  /**
27
   * @var iSerializer
28
   */
29
  private $serializer;
30
31
  /**
32
   * @var string
33
   */
34
  private $prefix = '';
35
36
  /**
37
   * @var bool
38
   */
39
  private $isReady = false;
40
41
  /**
42
   * @var bool
43
   */
44
  private $isActive = true;
45
46
  /**
47
   * @var mixed no cache, if admin-session is set
48
   */
49
  private $isAdminSession = false;
50
51
  /**
52
   * __construct
53
   *
54
   * @param null|iAdapter    $adapter
55
   * @param null|iSerializer $serializer
56
   * @param boolean          $checkForUser   check for dev-ip or if cms-user is logged-in
57
   * @param boolean          $cacheEnabled   false will disable the cache (use it e.g. for global settings)
58
   * @param string|boolean   $isAdminSession set a user-id, if the user is a admin (so we can disable cache for this
59
   *                                         user)
60
   */
61 37
  public function __construct($adapter = null, $serializer = null, $checkForUser = true, $cacheEnabled = true, $isAdminSession = false)
62
  {
63 37
    $this->isAdminSession = $isAdminSession;
64
65
    // First check if the cache is active at all.
66 37
    $this->setActive($cacheEnabled);
67 37
    if (
68
        $this->isActive === true
69
        &&
70
        $checkForUser === true
71 37
    ) {
72
      $this->setActive($this->isCacheActiveForTheCurrentUser());
73 37
    }
74
75
    // If the cache is active, then try to auto-connect to the best possible cache-system.
76
    if ($this->isActive === true) {
77 37
78 37
      $this->setPrefix($this->getTheDefaultPrefix());
79 37
80
      if (
81 37
          $adapter === null
82
          ||
83
          !is_object($adapter)
84
          ||
85
          !$adapter instanceof iAdapter
86 37
      ) {
87
        $adapter = $this->autoConnectToAvailableCacheSystem();
88
      }
89
90
      // INFO: Memcache(d) has his own "serializer", so don't use it twice
91 1
      if (!is_object($serializer) && $serializer === null) {
92
        if (
93
            $adapter instanceof AdapterMemcached
94
            ||
95
            $adapter instanceof AdapterMemcache
96
        ) {
97
          $serializer = new SerializerNo();
98 37
        } else {
99
          // set default serializer
100
          $serializer = new SerializerIgbinary();
101
        }
102
      }
103 37
    }
104
105 37
    // Final checks ...
106 37
    if (
107
        $serializer instanceof iSerializer
108 37
        &&
109 37
        $adapter instanceof iAdapter
110 37
    ) {
111 37
      $this->setCacheIsReady(true);
112
113
      $this->adapter = $adapter;
114
      $this->serializer = $serializer;
115
    }
116
  }
117
118 37
  /**
119
   * enable / disable the cache
120 37
   *
121 37
   * @param boolean $isActive
122
   */
123
  public function setActive($isActive)
124
  {
125
    $this->isActive = (boolean)$isActive;
126
  }
127
128
  /**
129
   * check if the current use is a admin || dev || server == client
130
   *
131
   * @return bool
132
   */
133
  public function isCacheActiveForTheCurrentUser()
0 ignored issues
show
Coding Style introduced by
isCacheActiveForTheCurrentUser uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
isCacheActiveForTheCurrentUser uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
134
  {
135
    $active = true;
136
137
    // test the cache, with this GET-parameter
138
    $testCache = isset($_GET['testCache']) ? (int)$_GET['testCache'] : 0;
139
140
    if ($testCache != 1) {
141
      if (
142
        // server == client
143
          (
144
              isset($_SERVER['SERVER_ADDR'])
145
              &&
146
              $_SERVER['SERVER_ADDR'] == $this->getClientIp()
147
          )
148
          ||
149
          // admin is logged-in
150
          $this->isAdminSession
151
          ||
152
          // user is a dev
153
          $this->checkForDev() === true
154
      ) {
155
        $active = false;
156
      }
157
    }
158
159
    return $active;
160
  }
161
162
  /**
163
   * returns the IP address of the client
164
   *
165
   * @param   bool $trust_proxy_headers   Whether or not to trust the
166
   *                                      proxy headers HTTP_CLIENT_IP
167
   *                                      and HTTP_X_FORWARDED_FOR. ONLY
168
   *                                      use if your $_SERVER is behind a
169
   *                                      proxy that sets these values
170
   *
171
   * @return  string
172
   */
173
  private function getClientIp($trust_proxy_headers = false)
0 ignored issues
show
Coding Style introduced by
getClientIp uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
174
  {
175
    $remoteAddr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'NO_REMOTE_ADDR';
176
177
    if ($trust_proxy_headers) {
178
      return $remoteAddr;
179
    }
180
181
    if (isset($_SERVER['HTTP_CLIENT_IP']) && $_SERVER['HTTP_CLIENT_IP']) {
182
      $ip = $_SERVER['HTTP_CLIENT_IP'];
183
    } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']) {
184
      $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
185
    } else {
186
      $ip = $remoteAddr;
187
    }
188
189
    return $ip;
190
  }
191
192
  /**
193
   * Check for local developer.
194
   *
195
   * @return bool
196
   */
197
  private function checkForDev()
0 ignored issues
show
Coding Style introduced by
checkForDev uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
checkForDev uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
198
  {
199
    $return = false;
200
201
    if (function_exists('checkForDev')) {
202
      $return = checkForDev();
203
    } else {
204
205
      // for testing with dev-address
206
      $noDev = isset($_GET['noDev']) ? (int)$_GET['noDev'] : 0;
207
      $remoteAddr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'NO_REMOTE_ADDR';
208
209
      if (
210
          $noDev != 1
211
          &&
212
          (
213
              $remoteAddr === '127.0.0.1'
214
              ||
215
              $remoteAddr === '::1'
216
              ||
217
              PHP_SAPI === 'cli'
218
          )
219
      ) {
220
        $return = true;
221
      }
222
    }
223
224
    return $return;
225 37
  }
226
227 37
  /**
228 37
   * Set the default-prefix via "SERVER"-var + "SESSION"-language.
229 37
   */
230 37
  protected function getTheDefaultPrefix()
0 ignored issues
show
Coding Style introduced by
getTheDefaultPrefix uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
getTheDefaultPrefix uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
231 37
  {
232
    return (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '') . '_' .
233
           (isset($_SERVER['THEME']) ? $_SERVER['THEME'] : '') . '_' .
234
           (isset($_SERVER['STAGE']) ? $_SERVER['STAGE'] : '') . '_' .
235
           (isset($_SESSION['language']) ? $_SESSION['language'] : '') . '_' .
236
           (isset($_SESSION['language_extra']) ? $_SESSION['language_extra'] : '');
237
  }
238
239
  /**
240
   * Auto-connect to the available cache-system on the server.
241
   *
242
   * @return iAdapter
243
   */
244
  protected function autoConnectToAvailableCacheSystem()
245
  {
246
    static $adapterCache;
247
248
    if (is_object($adapterCache) && $adapterCache instanceof iAdapter) {
249
      return $adapterCache;
250
    } else {
251
252
      $memcached = null;
253
      $isMemcachedAvailable = false;
254
      if (extension_loaded('memcached')) {
255
        $memcached = new \Memcached();
256
        /** @noinspection PhpUsageOfSilenceOperatorInspection */
257
        $isMemcachedAvailable = @$memcached->addServer('127.0.0.1', 11211);
258
      }
259
260
      if ($isMemcachedAvailable === false) {
261
        $memcached = null;
262
      }
263
264
      $adapterMemcached = new AdapterMemcached($memcached);
0 ignored issues
show
Bug introduced by
It seems like $memcached can be null; however, __construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
265
      if ($adapterMemcached->installed() === true) {
266
267
        // -------------------------------------------------------------
268
        // "Memcached"
269
        // -------------------------------------------------------------
270
        $adapter = $adapterMemcached;
271
272
      } else {
273
274
        $memcache = null;
275
        $isMemcacheAvailable = false;
276
        if (class_exists('\Memcache')) {
277
          $memcache = new \Memcache;
278
          /** @noinspection PhpUsageOfSilenceOperatorInspection */
279
          $isMemcacheAvailable = @$memcache->connect('127.0.0.1', 11211);
280
        }
281
282
        if ($isMemcacheAvailable === false) {
283
          $memcache = null;
284
        }
285
286
        $adapterMemcache = new AdapterMemcache($memcache);
0 ignored issues
show
Bug introduced by
It seems like $memcache can be null; however, __construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
287
        if ($adapterMemcache->installed() === true) {
288
289
          // -------------------------------------------------------------
290
          // "Memcache"
291
          // -------------------------------------------------------------
292
          $adapter = $adapterMemcache;
293
294
        } else {
295
296
          $redis = null;
297
          $isRedisAvailable = false;
298
          if (
299
              extension_loaded('redis')
300
              &&
301
              class_exists('\Predis\Client')
302
          ) {
303
            /** @noinspection PhpUndefinedNamespaceInspection */
304
            $redis = new \Predis\Client(
305
                array(
306
                    'scheme'  => 'tcp',
307
                    'host'    => '127.0.0.1',
308
                    'port'    => 6379,
309
                    'timeout' => '2.0',
310
                )
311
            );
312
            try {
313
              $redis->connect();
314
              $isRedisAvailable = $redis->getConnection()->isConnected();
315
            } catch (\Exception $e) {
316
              // nothing
317
            }
318
          }
319
320
          if ($isRedisAvailable === false) {
321
            $redis = null;
322
          }
323
324
          $adapterRedis = new AdapterPredis($redis);
0 ignored issues
show
Bug introduced by
It seems like $redis can be null; however, __construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
325
          if ($adapterRedis->installed() === true) {
326
327
            // -------------------------------------------------------------
328
            // Redis
329
            // -------------------------------------------------------------
330
            $adapter = $adapterRedis;
331
332
          } else {
333
334
            $adapterXcache = new AdapterXcache();
335
            if ($adapterXcache->installed() === true) {
336
337
              // fallback to Xcache
338
              $adapter = $adapterXcache;
339
340
            } else {
341
342
              $adapterApc = new AdapterApc();
343
              if ($adapterApc->installed() === true) {
344
345
                // -------------------------------------------------------------
346
                // "APC || APCu"
347
                // -------------------------------------------------------------
348
                $adapter = $adapterApc;
349
350
              } else {
351
352
                $adapterFile = new AdapterFile();
353
                if ($adapterFile->installed() === true) {
354
355
                  // -------------------------------------------------------------
356
                  // File-Cache
357
                  // -------------------------------------------------------------
358
                  $adapter = $adapterFile;
359
360
                } else {
361
362
                  // -------------------------------------------------------------
363
                  // Static-PHP-Cache
364
                  // -------------------------------------------------------------
365
                  $adapter = new AdapterArray();
366 37
                }
367
              }
368 37
            }
369 37
          }
370
        }
371
      }
372
373
      // save to static cache
374
      $adapterCache = $adapter;
375
    }
376 4
377
    return $adapter;
378 4
  }
379
380
  /**
381
   * Set "isReady" state.
382
   *
383
   * @param boolean $isReady
384
   */
385
  private function setCacheIsReady($isReady)
386
  {
387
    $this->isReady = (boolean)$isReady;
388 17
  }
389
390 17
  /**
391 17
   * Get the "isReady" state.
392 17
   *
393 17
   * @return boolean
394 17
   */
395
  public function getCacheIsReady()
396
  {
397
    return $this->isReady;
398 17
  }
399
400
  /**
401
   * Get cached-item by key.
402
   *
403
   * @param string $key
404
   *
405
   * @return mixed
406
   */
407
  public function getItem($key)
408 32
  {
409
    if ($this->adapter instanceof iAdapter) {
410 32
      $storeKey = $this->calculateStoreKey($key);
411
      $serialized = $this->adapter->get($storeKey);
412 32
      $value = $serialized ? $this->serializer->unserialize($serialized) : null;
413 6
    } else {
414 6
      return null;
415
    }
416 32
417
    return $value;
418
  }
419
420
  /**
421
   * Calculate store-key (prefix + $rawKey).
422
   *
423
   * @param string $rawKey
424 6
   *
425
   * @return string
426 6
   */
427 6
  private function calculateStoreKey($rawKey)
428 6
  {
429
    $str = $this->getPrefix() . $rawKey;
430 6
431 6
    if ($this->adapter instanceof AdapterFile) {
432 6
      $str = $this->cleanStoreKey($str);
433 6
    }
434 6
435 6
    return $str;
436 6
  }
437 6
438 6
  /**
439
   * Clean store-key (required e.g. for the "File"-Adapter).
440 6
   *
441 6
   * @param string $str
442 6
   *
443 6
   * @return string
444 6
   */
445 6
  private function cleanStoreKey($str)
446 6
  {
447
    $str = preg_replace("/[\r\n\t ]+/", ' ', $str);
448 6
    $str = str_replace(
449
        array('"', '*', ':', '<', '>', '?', "'", '|'),
450
        array(
451
            '-+-',
452
            '-+-+-',
453
            '-+-+-+-',
454 32
            '-+-+-+-+-',
455
            '-+-+-+-+-+-',
456 32
            '-+-+-+-+-+-+-',
457
            '-+-+-+-+-+-+-+-',
458
            '-+-+-+-+-+-+-+-+-',
459
        ),
460
        $str
461
    );
462
    $str = html_entity_decode($str, ENT_QUOTES, 'UTF-8');
463
    $str = htmlentities($str, ENT_QUOTES, 'UTF-8');
464 37
    $str = preg_replace('/(&)([a-z])([a-z]+;)/i', '$2', $str);
465
    $str = str_replace(' ', '-', $str);
466 37
    $str = rawurlencode($str);
467 37
    $str = str_replace('%', '-', $str);
468
469
    return $str;
470
  }
471
472
  /**
473
   * Get the prefix.
474
   *
475
   * @return string
476
   */
477
  public function getPrefix()
478
  {
479 6
    return $this->prefix;
480
  }
481 6
482
  /**
483 6
   * !!! Set the prefix. !!!
484 1
   *
485
   * WARNING: Do not use if you don't know what you do. Because this will overwrite the default prefix.
486
   *
487 5
   * @param string $prefix
488
   */
489 5
  public function setPrefix($prefix)
490
  {
491
    $this->prefix = (string)$prefix;
492
  }
493
494
  /**
495
   * Set cache-item by key => value + date.
496
   *
497
   * @param string    $key
498
   * @param mixed     $value
499
   * @param \DateTime $date
500
   *
501 17
   * @return boolean
502
   * @throws \Exception
503
   */
504 17
  public function setItemToDate($key, $value, \DateTime $date)
505 17
  {
506 17
    $ttl = $date->getTimestamp() - time();
507 17
508 17
    if ($ttl <= 0) {
509 17
      throw new \Exception('Date in the past.');
510
    }
511 17
512 7
    $storeKey = $this->calculateStoreKey($key);
513
514 10
    return $this->setItem($storeKey, $value, $ttl);
515
  }
516
517
  /**
518
   * Set cache-item by key => value + ttl.
519
   *
520
   * @param string $key
521
   * @param mixed  $value
522
   * @param int    $ttl
523
   *
524
   * @return bool
525
   */
526
  public function setItem($key, $value, $ttl = 0)
527
  {
528 2
    if (
529
        $this->adapter instanceof iAdapter
530 2
        &&
531 2
        $this->serializer instanceof iSerializer
532
    ) {
533 2
      $storeKey = $this->calculateStoreKey($key);
534
      $serialized = $this->serializer->serialize($value);
535
536
      if ($ttl) {
537
        return $this->adapter->setExpired($storeKey, $serialized, $ttl);
538
      } else {
539
        return $this->adapter->set($storeKey, $serialized);
540
      }
541
    } else {
542
      return false;
543
    }
544 1
  }
545
546 1
  /**
547 1
   * Remove a cached-item.
548
   *
549
   * @param string $key
550
   *
551
   * @return bool
552
   */
553 View Code Duplication
  public function removeItem($key)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
554
  {
555
    if ($this->adapter instanceof iAdapter) {
556
      $storeKey = $this->calculateStoreKey($key);
557
558
      return $this->adapter->remove($storeKey);
559
    } else {
560 6
      return false;
561
    }
562 6
  }
563 6
564
  /**
565 6
   * Remove all cached-items.
566
   *
567
   * @return bool
568
   */
569
  public function removeAll()
570
  {
571
    if ($this->adapter instanceof iAdapter) {
572
      return $this->adapter->removeAll();
573
    } else {
574
      return false;
575
    }
576
  }
577
578
  /**
579
   * Check if cached-item exists.
580
   *
581
   * @param string $key
582
   *
583
   * @return boolean
584
   */
585 View Code Duplication
  public function existsItem($key)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
586
  {
587
    if ($this->adapter instanceof iAdapter) {
588
      $storeKey = $this->calculateStoreKey($key);
589
590
      return $this->adapter->exists($storeKey);
591
    } else {
592
      return false;
593
    }
594
  }
595
596
  /**
597
   * Get the current adapter class-name.
598
   *
599
   * @return string
600
   */
601
  public function getUsedAdapterClassName()
602
  {
603
    return get_class($this->adapter);
604
  }
605
606
  /**
607
   * Get the current serializer class-name.
608
   *
609
   * @return string
610
   */
611
  public function getUsedSerializerClassName()
612
  {
613
    return get_class($this->serializer);
614
  }
615
}
616