chadicus /
marvel-api-client
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 Chadicus\Marvel\Api\Cache; |
||
| 4 | |||
| 5 | /** |
||
| 6 | * Base class for all cache objects. |
||
| 7 | */ |
||
| 8 | abstract class AbstractCache implements CacheInterface |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Default time to live in seconds. |
||
| 12 | * |
||
| 13 | * @var integer |
||
| 14 | */ |
||
| 15 | private $defaultTimeToLive = CacheInterface::MAX_TTL; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Sets the default time to live in seconds. |
||
| 19 | * |
||
| 20 | * @param integer $defaultTimeToLive The time in seconds. |
||
| 21 | * |
||
| 22 | * @return void |
||
| 23 | */ |
||
| 24 | final public function setDefaultTTL(int $defaultTimeToLive) |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 25 | { |
||
| 26 | $this->defaultTimeToLive = self::ensureTTL($defaultTimeToLive); |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Returns the default time to live in seconds. |
||
| 31 | * |
||
| 32 | * @return integer The time in seconds. |
||
| 33 | */ |
||
| 34 | final public function getDefaultTTL() |
||
| 35 | { |
||
| 36 | return $this->defaultTimeToLive; |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Helper method to check TTL value. |
||
| 41 | * |
||
| 42 | * @param integer $ttl The time value to check in seconds. |
||
| 43 | * |
||
| 44 | * @return integer The valid $ttl value. |
||
| 45 | * |
||
| 46 | * @throws \InvalidArgumentException Thrown if $ttl is < 1 or > CacheInterface::MAX_TTL. |
||
| 47 | */ |
||
| 48 | final protected static function ensureTTL(int $ttl) |
||
|
0 ignored issues
–
show
|
|||
| 49 | { |
||
| 50 | if ($ttl < 1 || $ttl > CacheInterface::MAX_TTL) { |
||
| 51 | throw new \InvalidArgumentException('TTL value must be an integer >= 1 and <= ' . CacheInterface::MAX_TTL); |
||
| 52 | } |
||
| 53 | |||
| 54 | return $ttl; |
||
| 55 | } |
||
| 56 | } |
||
| 57 |