TaggedRepository::getKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Translation\Cache;
4
5
use Illuminate\Contracts\Cache\Store;
6
7
class TaggedRepository implements CacheRepositoryInterface
8
{
9
    /**
10
     * The cache store implementation.
11
     *
12
     * @var \Illuminate\Contracts\Cache\Store
13
     */
14
    protected $store;
15
16
    /**
17
     * The translation cache tag
18
     *
19
     * @var string
20
     */
21
    protected $cacheTag;
22
23
    /**
24
     * Create a new cache repository instance.
25
     *
26
     * @param  \Illuminate\Contracts\Cache\Store $store
27
     * @return void
28
     */
29
    public function __construct(Store $store, $cacheTag)
30
    {
31
        $this->store    = $store;
32
        $this->cacheTag = $cacheTag;
33
    }
34
35
    /**
36
     *  Checks if an entry with the given key exists in the cache.
37
     *
38
     * @param  string $locale
39
     * @param  string $group
40
     * @param  string $namespace
41
     * @return boolean
42
     */
43
    public function has($locale, $group, $namespace)
44
    {
45
        return !is_null($this->get($locale, $group, $namespace));
46
    }
47
48
    /**
49
     *  Get an item from the cache
50
     *
51
     * @param  string $locale
52
     * @param  string $group
53
     * @param  string $namespace
54
     * @return mixed
55
     */
56
    public function get($locale, $group, $namespace)
57
    {
58
        $key = $this->getKey($locale, $group, $namespace);
59
        return $this->store->tags([$this->cacheTag, $key])->get($key);
0 ignored issues
show
Bug introduced by
The method tags() does not exist on Illuminate\Contracts\Cache\Store. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
        return $this->store->/** @scrutinizer ignore-call */ tags([$this->cacheTag, $key])->get($key);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60
    }
61
62
    /**
63
     *  Put an item into the cache store
64
     *
65
     * @param  string  $locale
66
     * @param  string  $group
67
     * @param  string  $namespace
68
     * @param  mixed   $content
69
     * @param  integer $minutes
70
     * @return void
71
     */
72
    public function put($locale, $group, $namespace, $content, $minutes)
73
    {
74
        $key = $this->getKey($locale, $group, $namespace);
75
        $this->store->tags([$this->cacheTag, $key])->put($key, $content, $minutes);
76
    }
77
78
    /**
79
     *  Flush the cache for the given entries
80
     *
81
     * @param  string $locale
82
     * @param  string $group
83
     * @param  string $namespace
84
     * @return void
85
     */
86
    public function flush($locale, $group, $namespace)
87
    {
88
        $key = $this->getKey($locale, $group, $namespace);
89
        $this->store->tags([$key])->flush();
90
    }
91
92
    /**
93
     *  Completely flush the cache
94
     *
95
     * @param  string $locale
96
     * @param  string $group
97
     * @param  string $namespace
98
     * @return void
99
     */
100
    public function flushAll()
101
    {
102
        $this->store->tags([$this->cacheTag])->flush();
103
    }
104
105
    /**
106
     *  Returns a unique cache key.
107
     *
108
     * @param  string $locale
109
     * @param  string $group
110
     * @param  string $namespace
111
     * @return string
112
     */
113
    protected function getKey($locale, $group, $namespace)
114
    {
115
        return md5("{$this->cacheTag}-{$locale}-{$group}-{$namespace}");
116
    }
117
}
118