1 | <?php |
||
9 | final class CacheItem implements CacheItemInterface |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * |
||
14 | * @var string |
||
15 | */ |
||
16 | private $key; |
||
17 | |||
18 | /** |
||
19 | * |
||
20 | * @var mixed |
||
21 | */ |
||
22 | private $value; |
||
23 | |||
24 | /** |
||
25 | * |
||
26 | * @var boolean |
||
27 | 5 | */ |
|
28 | private $isHit; |
||
29 | 5 | ||
30 | 5 | /** |
|
31 | 5 | * |
|
32 | 5 | * @var null DateTimeInterface |
|
33 | */ |
||
34 | private $expires; |
||
35 | |||
36 | public function __construct($key, $value, $isHit, DateTimeInterface $expires = null) |
||
43 | |||
44 | 2 | /** |
|
45 | * Returns the key for the current cache item. |
||
46 | * |
||
47 | * The key is loaded by the Implementing Library, but should be available to |
||
48 | * the higher level callers when needed. |
||
49 | * |
||
50 | * @return string The key string for this cache item. |
||
51 | */ |
||
52 | public function getKey() |
||
56 | |||
57 | /** |
||
58 | 3 | * Retrieves the value of the item from the cache associated with this object's key. |
|
59 | * |
||
60 | 3 | * The value returned must be identical to the value originally stored by set(). |
|
61 | * |
||
62 | * If isHit() returns false, this method MUST return null. Note that null |
||
63 | * is a legitimate cached value, so the isHit() method SHOULD be used to |
||
64 | * differentiate between "null value was found" and "no value was found." |
||
65 | * |
||
66 | * @return mixed The value corresponding to this cache item's key, or null if not found. |
||
67 | */ |
||
68 | public function get() |
||
76 | |||
77 | public function setIsHit($mode = true) |
||
81 | |||
82 | /** |
||
83 | * Confirms if the cache item lookup resulted in a cache hit. |
||
84 | * |
||
85 | * Note: This method MUST NOT have a race condition between calling isHit() |
||
86 | * and calling get(). |
||
87 | * |
||
88 | 1 | * @return bool True if the request resulted in a cache hit. False otherwise. |
|
89 | */ |
||
90 | 1 | public function isHit() |
|
94 | |||
95 | /** |
||
96 | * |
||
97 | * @return DateTimeInterface null |
||
98 | */ |
||
99 | public function getExpires() |
||
103 | |||
104 | /** |
||
105 | * Sets the value represented by this cache item. |
||
106 | 1 | * |
|
107 | * The $value argument may be any item that can be serialized by PHP, |
||
108 | 1 | * although the method of serialization is left up to the Implementing |
|
109 | * Library. |
||
110 | * |
||
111 | * @param mixed $value |
||
112 | * The serializable value to be stored. |
||
113 | * |
||
114 | * @return static The invoked object. |
||
115 | */ |
||
116 | public function set($value) |
||
122 | |||
123 | 1 | /** |
|
124 | * Sets the expiration time for this cache item. |
||
125 | 1 | * |
|
126 | * @param \DateTimeInterface $expires |
||
127 | * The point in time after which the item MUST be considered expired. |
||
128 | * If null is passed explicitly, a default value MAY be used. If none is set, |
||
129 | * the value should be stored permanently or for as long as the |
||
130 | * implementation allows. |
||
131 | * |
||
132 | * @return static The called object. |
||
133 | */ |
||
134 | public function expiresAt($expires) |
||
144 | |||
145 | /** |
||
146 | * Sets the expiration time for this cache item. |
||
147 | * |
||
148 | * @param int|\DateInterval $time |
||
149 | * The period of time from the present after which the item MUST be considered |
||
150 | * expired. An integer parameter is understood to be the time in seconds until |
||
151 | * expiration. If null is passed explicitly, a default value MAY be used. |
||
152 | * If none is set, the value should be stored permanently or for as long as the |
||
153 | * implementation allows. |
||
154 | * |
||
155 | * @return static The called object. |
||
156 | */ |
||
157 | public function expiresAfter($time) |
||
174 | } |
||
175 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.