Skip to content

Commit

Permalink
Add return types
Browse files Browse the repository at this point in the history
This is a breaking change since implementations without return types are considered to be "widening" them, which is not allowed in PHP.

Implementations that implement v3, however, are also implementing v1 and v2 as of PHP 7.4, so such implementations can use a require statement of `^1|^2|^3`.  Usage libraries also can use a require statement of `^1|^2|^3`
  • Loading branch information
navarr committed Aug 27, 2021
1 parent 0f32180 commit 19a4d7c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
"dev-master": "3.0.x-dev"
}
}
}
16 changes: 8 additions & 8 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(string $key, mixed $default = null);
public function get(string $key, mixed $default = null): mixed;

/**
* 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(string $key, mixed $default = null);
* @throws \Psr\SimpleCache\InvalidArgumentException
* MUST be thrown if the $key string is not a legal value.
*/
public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null);
public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool;

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

/**
* Wipes clean the entire cache's keys.
*
* @return bool True on success and false on failure.
*/
public function clear();
public function clear(): bool;

/**
* Obtains multiple cache items by their unique keys.
Expand All @@ -64,7 +64,7 @@ public function clear();
* 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(iterable $keys, mixed $default = null);
public function getMultiple(iterable $keys, mixed $default = null): iterable;

/**
* Persists a set of key => value pairs in the cache, with an optional TTL.
Expand All @@ -80,7 +80,7 @@ public function getMultiple(iterable $keys, mixed $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(iterable $values, null|int|\DateInterval $ttl = null);
public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool;

/**
* Deletes multiple cache items in a single operation.
Expand All @@ -93,7 +93,7 @@ public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null
* 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(iterable $keys);
public function deleteMultiple(iterable $keys): bool;

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

0 comments on commit 19a4d7c

Please sign in to comment.