Completed
Push — master ( d0dd0d...df62c5 )
by ARCANEDEV
12s
created

src/Cache.php (2 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php namespace Arcanedev\GeoIP;
2
3
use Arcanedev\GeoIP\Contracts\GeoIPCache;
4
use Illuminate\Contracts\Cache\Repository as Store;
5
6
/**
7
 * Class     Cache
8
 *
9
 * @package  Arcanedev\GeoIP
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class Cache implements GeoIPCache
13
{
14
    /* ------------------------------------------------------------------------------------------------
15
     |  Properties
16
     | ------------------------------------------------------------------------------------------------
17
     */
18
    /** @var  \Illuminate\Contracts\Cache\Repository */
19
    protected $store;
20
21
    /** @var array */
22
    protected $tags = [];
23
24
    /** @var int */
25
    protected $expires = 30;
26
27
    /* ------------------------------------------------------------------------------------------------
28
     |  Constructor
29
     | ------------------------------------------------------------------------------------------------
30
     */
31
    /**
32
     * Cache constructor.
33
     *
34
     * @param  \Illuminate\Contracts\Cache\Repository  $store
35
     * @param  array                                   $tags
36
     * @param  int                                     $expires
37
     */
38 36
    public function __construct(Store $store, array $tags, $expires = 30)
39
    {
40 36
        $this->store   = $store;
41 36
        $this->tags    = $tags;
42 36
        $this->expires = $expires;
43 36
    }
44
45
    /* ------------------------------------------------------------------------------------------------
46
     |  Getters & Setters
47
     | ------------------------------------------------------------------------------------------------
48
     */
49
    /**
50
     * Get the store instance.
51
     *
52
     * @return \Illuminate\Contracts\Cache\Repository
53
     */
54 12
    private function store()
55
    {
56 12
        return empty($this->tags) ? $this->store : $this->store->tags($this->tags);
0 ignored issues
show
The method tags() does not seem to exist on object<Illuminate\Contracts\Cache\Repository>.

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...
57
    }
58
59
    /* ------------------------------------------------------------------------------------------------
60
     |  Main Functions
61
     | ------------------------------------------------------------------------------------------------
62
     */
63
    /**
64
     * Get an item from the cache.
65
     *
66
     * @param  string  $key
67
     *
68
     * @return \Arcanedev\GeoIP\Location|null
69
     */
70 12
    public function get($key)
71
    {
72 12
        return is_array($value = $this->store()->get($key)) ? new Location($value) : null;
73
    }
74
75
    /**
76
     * Store an item in cache.
77
     *
78
     * @param  string  $key
79
     * @param  array   $location
80
     */
81 12
    public function set($key, array $location)
82
    {
83 12
        $this->store()->put($key, $location, $this->expires);
84 12
    }
85
86
    /**
87
     * Flush cache for tags.
88
     */
89
    public function flush()
90
    {
91
        $this->store()->flush();
0 ignored issues
show
The method flush() does not seem to exist on object<Illuminate\Contracts\Cache\Repository>.

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...
92
    }
93
}
94