Completed
Push — master ( cc24d0...5b3757 )
by Marcel
08:43
created

src/Cache/CodeIgniterCache.php (1 issue)

duplicate/similar methods.

Duplication Informational

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
2
3
namespace BotMan\BotMan\Cache;
4
5
use BotMan\BotMan\Interfaces\CacheInterface;
6
7
class CodeIgniterCache implements CacheInterface
8
{
9
    /**
10
     * @var array
11
     */
12
    private $cache;
13
14
    /**
15
     * @param array $driver
16
     */
17
    public function __construct($driver)
18
    {
19
        $this->cache = $driver;
20
    }
21
22
    /**
23
     * Determine if an item exists in the cache.
24
     *
25
     * @param  string $key
26
     * @return bool
27
     */
28
    public function has($key)
29
    {
30
        return $this->cache->get($key) !== false;
31
    }
32
33
    /**
34
     * Retrieve an item from the cache by key.
35
     *
36
     * @param  string $key
37
     * @param  mixed $default
38
     * @return mixed
39
     */
40
    public function get($key, $default = null)
41
    {
42
        if ($this->has($key)) {
43
            return $this->cache->get($key);
44
        }
45
46
        return $default;
47
    }
48
49
    /**
50
     * Retrieve an item from the cache and delete it.
51
     *
52
     * @param  string $key
53
     * @param  mixed $default
54
     * @return mixed
55
     */
56
    public function pull($key, $default = null)
57
    {
58
        if ($this->has($key)) {
59
            $cached = $this->cache->get($key);
60
            $this->cache->delete($key);
61
62
            return $cached;
63
        }
64
65
        return $default;
66
    }
67
68
    /**
69
     * Store an item in the cache.
70
     *
71
     * @param  string $key
72
     * @param  mixed $value
73
     * @param  \DateTime|int $minutes
74
     * @return void
75
     */
76 View Code Duplication
    public function put($key, $value, $minutes)
0 ignored issues
show
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...
77
    {
78
        if ($minutes instanceof \Datetime) {
79
            $seconds = $minutes->getTimestamp() - time();
80
        } else {
81
            $seconds = $minutes * 60;
82
        }
83
84
        $this->cache->save($key, $value, $seconds);
85
    }
86
}
87