Skip to content

Commit

Permalink
Merge pull request #414 from iclukas/296-Extend_function_doesn't_work
Browse files Browse the repository at this point in the history
implemented Item::extend(), fixed some PHPDoc inconsistencies
  • Loading branch information
tedivm authored May 31, 2022
2 parents e6d5534 + 539afc6 commit 70767dc
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions src/Stash/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public function setInvalidationMethod($invalidation = Invalidation::PRECOMPUTE,
/**
* {@inheritdoc}
*
* @param string $invalidation
* @param int $invalidation
* @param mixed $arg
* @param mixed $arg2
* @return mixed|Null
Expand Down Expand Up @@ -357,7 +357,7 @@ public function isMiss()
* {@inheritdoc}
*
* @param int $ttl time to live
* @return object data with new expiration date
* @return bool
*/
public function lock($ttl = null)
{
Expand All @@ -384,7 +384,7 @@ public function lock($ttl = null)
* {@inheritdoc}
*
* @param mixed $value
* @return \Stash\Item
* @return \Stash\Item|false
*/
public function set($value)
{
Expand Down Expand Up @@ -523,16 +523,34 @@ private function executeSet($data, $time)
/**
* {@inheritdoc}
*
* @param int $ttl time to live
* @return bool
* @param int|\DateInterval $ttl time to live
* @return \Stash\Item|false
*/
public function extend($ttl = null)
{
if ($this->isDisabled()) {
return false;
}

return $this->set($this->get(), $ttl);
$expiration = $this->getExpiration();

if (is_numeric($ttl)) {
$dateInterval = \DateInterval::createFromDateString(abs($ttl) . ' seconds');
if ($ttl > 0) {
$expiration->add($dateInterval);
} else {
$expiration->sub($dateInterval);
}
} elseif ($ttl instanceof \DateInterval) {
$expiration->add($ttl);
} else {
$expiration = null;
}

if ($this->executeSet($this->get(), $expiration)) {
return $this;
}
return false;
}

/**
Expand Down Expand Up @@ -574,7 +592,7 @@ protected function logException($message, $exception)
$message,
array(
'exception' => $exception,
'key' => $this->keyString
'key' => $this->keyString
)
);

Expand Down Expand Up @@ -715,7 +733,7 @@ protected function validateRecord($validation, &$record)
/**
* {@inheritdoc}
*
* @return \DateTime
* @return \DateTime|false
*/
public function getCreation()
{
Expand All @@ -733,7 +751,7 @@ public function getCreation()
/**
* {@inheritdoc}
*
* @return int date timestamp
* @return \DateTime date timestamp
*/
public function getExpiration()
{
Expand Down

0 comments on commit 70767dc

Please sign in to comment.