IlluminateCacheAdapter::cache()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 8
ccs 3
cts 4
cp 0.75
rs 9.4286
cc 2
eloc 4
nc 2
nop 0
crap 2.0625
1
<?php
2
3
namespace Tymon\JWTAuth\Providers\Storage;
4
5
use Illuminate\Cache\CacheManager;
6
use Tymon\JWTAuth\Providers\Storage\StorageInterface;
7
8
class IlluminateCacheAdapter implements StorageInterface
9
{
10
    /**
11
     * @var \Illuminate\Cache\CacheManager
12
     */
13
    protected $cache;
14
15
    /**
16
     * @var string
17
     */
18
    protected $tag = 'tymon.jwt';
19
20
    /**
21
     * @param \Illuminate\Cache\CacheManager  $cache
22
     */
23 12
    public function __construct(CacheManager $cache)
24
    {
25 12
        $this->cache = $cache;
26 12
    }
27
28
    /**
29
     * Add a new item into storage
30
     *
31
     * @param  string  $key
32
     * @param  mixed  $value
33
     * @param  int  $minutes
34
     * @return void
35
     */
36 3
    public function add($key, $value, $minutes)
37
    {
38 3
        $this->cache()->put($key, $value, $minutes);
39 3
    }
40
41
    /**
42
     * Check whether a key exists in storage
43
     *
44
     * @param  string  $key
45
     * @return bool
46
     */
47 3
    public function has($key)
48
    {
49 3
        return $this->cache()->has($key);
50
    }
51
52
    /**
53
     * Remove an item from storage
54
     *
55
     * @param  string  $key
56
     * @return bool
57
     */
58 3
    public function destroy($key)
59
    {
60 3
        return $this->cache()->forget($key);
61
    }
62
63
    /**
64
     * Remove all items associated with the tag
65
     *
66
     * @return void
67
     */
68 3
    public function flush()
69
    {
70 3
        $this->cache()->flush();
71 3
    }
72
73
    /**
74
     * Return the cache instance with tags attached
75
     *
76
     * @return \Illuminate\Cache\CacheManager
77
     */
78 12
    protected function cache()
79
    {
80 12
        if (! method_exists($this->cache, 'tags')) {
81 12
            return $this->cache;
82
        }
83
84
        return $this->cache->tags($this->tag);
85
    }
86
}
87