| Total Complexity | 13 |
| Total Lines | 112 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class CacheItem implements CacheItemInterface |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var string |
||
| 13 | */ |
||
| 14 | private $key; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var mixed|null |
||
| 18 | */ |
||
| 19 | private $value; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var bool |
||
| 23 | */ |
||
| 24 | private $hit; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var \DateTimeInterface |
||
| 28 | */ |
||
| 29 | private $expires; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param string $key |
||
| 33 | * @param mixed $value |
||
| 34 | * @param bool $hit |
||
| 35 | */ |
||
| 36 | public function __construct($key, $value = null, $hit = false) |
||
| 37 | { |
||
| 38 | $this->key = $key; |
||
| 39 | $this->hit = boolval($hit); |
||
| 40 | $this->value = $this->hit ? $value : null; |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * {@inheritdoc} |
||
| 45 | */ |
||
| 46 | public function getKey() |
||
| 47 | { |
||
| 48 | return $this->key; |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * {@inheritdoc} |
||
| 53 | */ |
||
| 54 | public function get() |
||
| 55 | { |
||
| 56 | return $this->value; |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * {@inheritdoc} |
||
| 61 | */ |
||
| 62 | public function isHit() |
||
| 63 | { |
||
| 64 | return $this->hit; |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * {@inheritdoc} |
||
| 69 | */ |
||
| 70 | public function set($value) |
||
| 71 | { |
||
| 72 | $this->value = $value; |
||
| 73 | |||
| 74 | return $this; |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * {@inheritdoc} |
||
| 79 | */ |
||
| 80 | public function expiresAt($expires) |
||
| 81 | { |
||
| 82 | if ($expires instanceof DateTimeInterface && ! $expires instanceof DateTimeImmutable) { |
||
| 83 | $timezone = $expires->getTimezone(); |
||
| 84 | $expires = DateTimeImmutable::createFromFormat('U', (string) $expires->getTimestamp(), $timezone); |
||
| 85 | $expires->setTimezone($timezone); |
||
| 86 | } |
||
| 87 | |||
| 88 | $this->expires = $expires; |
||
| 89 | |||
| 90 | return $this; |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * {@inheritdoc} |
||
| 95 | */ |
||
| 96 | public function expiresAfter($time) |
||
| 97 | { |
||
| 98 | if ($time === null) { |
||
| 99 | $this->expires = null; |
||
| 100 | |||
| 101 | return; |
||
| 102 | } |
||
| 103 | |||
| 104 | $this->expires = new DateTimeImmutable(); |
||
| 105 | |||
| 106 | if (! $time instanceof DateInterval) { |
||
| 107 | $time = new DateInterval(sprintf('PT%sS', $time)); |
||
| 108 | } |
||
| 109 | |||
| 110 | $this->expires = $this->expires->add($time); |
||
| 111 | |||
| 112 | return $this; |
||
| 113 | } |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @return \DateTimeInterface |
||
| 117 | */ |
||
| 118 | public function getExpiresAt() |
||
| 121 | } |
||
| 122 | } |
||
| 123 |