Skip to content

Commit

Permalink
Merge pull request #25 from php-fig/param-types
Browse files Browse the repository at this point in the history
Add Parameter Types (versions 2 of the library)
  • Loading branch information
Jean85 authored Oct 29, 2021
2 parents 66e27ef + dd145de commit 8707bf3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"php": ">=5.3.0"
"php": ">=8.0.0"
},
"autoload": {
"psr-4": {
Expand All @@ -19,7 +19,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "2.0.x-dev"
}
}
}
2 changes: 1 addition & 1 deletion src/CacheException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
/**
* Interface used for all types of exceptions thrown by the implementing library.
*/
interface CacheException
interface CacheException extends \Throwable
{
}
22 changes: 11 additions & 11 deletions src/CacheInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface CacheInterface
* @throws \Psr\SimpleCache\InvalidArgumentException
* MUST be thrown if the $key string is not a legal value.
*/
public function get($key, $default = null);
public function get(string $key, mixed $default = null);

/**
* Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
Expand All @@ -31,7 +31,7 @@ public function get($key, $default = null);
* @throws \Psr\SimpleCache\InvalidArgumentException
* MUST be thrown if the $key string is not a legal value.
*/
public function set($key, $value, $ttl = null);
public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null);

/**
* Delete an item from the cache by its unique key.
Expand All @@ -43,7 +43,7 @@ public function set($key, $value, $ttl = null);
* @throws \Psr\SimpleCache\InvalidArgumentException
* MUST be thrown if the $key string is not a legal value.
*/
public function delete($key);
public function delete(string $key);

/**
* Wipes clean the entire cache's keys.
Expand All @@ -55,16 +55,16 @@ public function clear();
/**
* Obtains multiple cache items by their unique keys.
*
* @param iterable $keys A list of keys that can be obtained in a single operation.
* @param mixed $default Default value to return for keys that do not exist.
* @param iterable<string> $keys A list of keys that can be obtained in a single operation.
* @param mixed $default Default value to return for keys that do not exist.
*
* @return iterable A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value.
* @return iterable<string, mixed> A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value.
*
* @throws \Psr\SimpleCache\InvalidArgumentException
* MUST be thrown if $keys is neither an array nor a Traversable,
* or if any of the $keys are not a legal value.
*/
public function getMultiple($keys, $default = null);
public function getMultiple(iterable $keys, mixed $default = null);

/**
* Persists a set of key => value pairs in the cache, with an optional TTL.
Expand All @@ -80,20 +80,20 @@ public function getMultiple($keys, $default = null);
* MUST be thrown if $values is neither an array nor a Traversable,
* or if any of the $values are not a legal value.
*/
public function setMultiple($values, $ttl = null);
public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null);

/**
* Deletes multiple cache items in a single operation.
*
* @param iterable $keys A list of string-based keys to be deleted.
* @param iterable<string> $keys A list of string-based keys to be deleted.
*
* @return bool True if the items were successfully removed. False if there was an error.
*
* @throws \Psr\SimpleCache\InvalidArgumentException
* MUST be thrown if $keys is neither an array nor a Traversable,
* or if any of the $keys are not a legal value.
*/
public function deleteMultiple($keys);
public function deleteMultiple(iterable $keys);

/**
* Determines whether an item is present in the cache.
Expand All @@ -110,5 +110,5 @@ public function deleteMultiple($keys);
* @throws \Psr\SimpleCache\InvalidArgumentException
* MUST be thrown if the $key string is not a legal value.
*/
public function has($key);
public function has(string $key);
}

0 comments on commit 8707bf3

Please sign in to comment.