Completed
Push — master ( f21d3b...aa6feb )
by Martin
04:21
created

CacheItem::expiresAfter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
namespace Psr6NullCache;
3
4
use Psr\Cache\CacheItemInterface;
5
6
final class CacheItem implements CacheItemInterface
7
{
8
9
    /**
10
     *
11
     * @var string
12
     */
13
    private $key;
14
15
    /**
16
     *
17
     * @var mixed
18
     */
19
    private $value;
20
21
    /**
22
     *
23
     * @var boolean
24
     */
25
    private $isHit;
26
27 5
    public function __construct($key, $value, $isHit)
28
    {
29 5
        $this->key = $key;
30 5
        $this->value = $value;
31 5
        $this->isHit = (bool) $isHit;
32 5
    }
33
34
    /**
35
     * Returns the key for the current cache item.
36
     *
37
     * The key is loaded by the Implementing Library, but should be available to
38
     * the higher level callers when needed.
39
     *
40
     * @return string The key string for this cache item.
41
     */
42 2
    public function getKey()
43
    {
44 2
        return $this->key;
45
    }
46
47
    /**
48
     * Retrieves the value of the item from the cache associated with this object's key.
49
     *
50
     * The value returned must be identical to the value originally stored by set().
51
     *
52
     * If isHit() returns false, this method MUST return null. Note that null
53
     * is a legitimate cached value, so the isHit() method SHOULD be used to
54
     * differentiate between "null value was found" and "no value was found."
55
     *
56
     * @return mixed The value corresponding to this cache item's key, or null if not found.
57
     */
58 3
    public function get()
59
    {
60 3
        return $this->value;
61
    }
62
63
    /**
64
     * Confirms if the cache item lookup resulted in a cache hit.
65
     *
66
     * Note: This method MUST NOT have a race condition between calling isHit()
67
     * and calling get().
68
     *
69
     * @return bool True if the request resulted in a cache hit. False otherwise.
70
     */
71 2
    public function isHit()
72
    {
73 2
        return $this->isHit;
74
    }
75
76
    /**
77
     * Sets the value represented by this cache item.
78
     *
79
     * The $value argument may be any item that can be serialized by PHP,
80
     * although the method of serialization is left up to the Implementing
81
     * Library.
82
     *
83
     * @param mixed $value
84
     *            The serializable value to be stored.
85
     *            
86
     * @return static The invoked object.
87
     */
88 1
    public function set($value)
89
    {
90 1
        $this->value = $value;
91
        
92 1
        return $this;
93
    }
94
95
    /**
96
     * Sets the expiration time for this cache item.
97
     *
98
     * @param \DateTimeInterface $expiration
99
     *            The point in time after which the item MUST be considered expired.
100
     *            If null is passed explicitly, a default value MAY be used. If none is set,
101
     *            the value should be stored permanently or for as long as the
102
     *            implementation allows.
103
     *            
104
     * @return static The called object.
105
     */
106 1
    public function expiresAt($expiration)
107
    {
108 1
        return $this;
109
    }
110
111
    /**
112
     * Sets the expiration time for this cache item.
113
     *
114
     * @param int|\DateInterval $time
115
     *            The period of time from the present after which the item MUST be considered
116
     *            expired. An integer parameter is understood to be the time in seconds until
117
     *            expiration. If null is passed explicitly, a default value MAY be used.
118
     *            If none is set, the value should be stored permanently or for as long as the
119
     *            implementation allows.
120
     *            
121
     * @return static The called object.
122
     */
123 1
    public function expiresAfter($time)
124
    {
125 1
        return $this;
126
    }
127
}
128