Skip to content
Snippets Groups Projects
Commit 866df1b6 authored by Tim van Dijen's avatar Tim van Dijen
Browse files

Fully typehint lib/Store/*.php

parent 6d0b22e4
No related branches found
No related tags found
No related merge requests found
......@@ -40,11 +40,8 @@ class Memcache extends Store
* @param string $key The key.
* @return mixed|null The value.
*/
public function get($type, $key)
public function get(string $type, string $key)
{
Assert::string($type);
Assert::string($key);
return \SimpleSAML\Memcache::get($this->prefix . '.' . $type . '.' . $key);
}
......@@ -58,10 +55,8 @@ class Memcache extends Store
* @param int|null $expire The expiration time (unix timestamp), or NULL if it never expires.
* @return void
*/
public function set($type, $key, $value, $expire = null)
public function set(string $type, string $key, $value, ?int $expire = null): void
{
Assert::string($type);
Assert::string($key);
Assert::nullOrGreaterThan($expire, 2592000);
if ($expire === null) {
......@@ -79,11 +74,8 @@ class Memcache extends Store
* @param string $key The key.
* @return void
*/
public function delete($type, $key)
public function delete(string $type, string $key): void
{
Assert::string($type);
Assert::string($key);
\SimpleSAML\Memcache::delete($this->prefix . '.' . $type . '.' . $key);
}
}
......@@ -77,11 +77,8 @@ class Redis extends Store
*
* @return mixed|null The value associated with that key, or null if there's no such key.
*/
public function get($type, $key)
public function get(string $type, string $key)
{
Assert::string($type);
Assert::string($key);
$result = $this->redis->get("{$type}.{$key}");
if ($result === false || $result === null) {
......@@ -101,10 +98,8 @@ class Redis extends Store
* @param int|null $expire The expiration time (unix timestamp), or null if it never expires.
* @return void
*/
public function set($type, $key, $value, $expire = null)
public function set(string $type, string $key, $value, ?int $expire = null): void
{
Assert::string($type);
Assert::string($key);
Assert::nullOrGreaterThan($expire, 2592000);
$serialized = serialize($value);
......@@ -125,11 +120,8 @@ class Redis extends Store
* @param string $key The key to delete.
* @return void
*/
public function delete($type, $key)
public function delete(string $type, string $key): void
{
Assert::string($type);
Assert::string($key);
$this->redis->del("{$type}.{$key}");
}
}
......@@ -84,7 +84,7 @@ class SQL extends Store
* Initialize the table-version table.
* @return void
*/
private function initTableVersionTable()
private function initTableVersionTable(): void
{
$this->tableVersions = [];
......@@ -108,7 +108,7 @@ class SQL extends Store
* Initialize key-value table.
* @return void
*/
private function initKVTable()
private function initKVTable(): void
{
$current_version = $this->getTableVersion('kvstore');
......@@ -188,10 +188,8 @@ class SQL extends Store
*
* @return int The table version, or 0 if the table doesn't exist.
*/
public function getTableVersion($name)
public function getTableVersion(string $name): int
{
Assert::string($name);
if (!isset($this->tableVersions[$name])) {
return 0;
}
......@@ -207,11 +205,8 @@ class SQL extends Store
* @param int $version Table version.
* @return void
*/
public function setTableVersion($name, $version)
public function setTableVersion(string $name, int $version): void
{
Assert::string($name);
Assert::integer($version);
$this->insertOrUpdate(
$this->prefix . '_tableVersion',
['_name'],
......@@ -231,10 +226,8 @@ class SQL extends Store
* @param array $data Associative array with columns.
* @return void
*/
public function insertOrUpdate($table, array $keys, array $data)
public function insertOrUpdate(string $table, array $keys, array $data): void
{
Assert::string($table);
$colNames = '(' . implode(', ', array_keys($data)) . ')';
$values = 'VALUES(:' . implode(', :', array_keys($data)) . ')';
......@@ -289,7 +282,7 @@ class SQL extends Store
* Clean the key-value table of expired entries.
* @return void
*/
private function cleanKVStore()
private function cleanKVStore(): void
{
Logger::debug('store.sql: Cleaning key-value store.');
......@@ -309,11 +302,8 @@ class SQL extends Store
*
* @return mixed|null The value associated with that key, or null if there's no such key.
*/
public function get($type, $key)
public function get(string $type, string $key)
{
Assert::string($type);
Assert::string($key);
if (strlen($key) > 50) {
$key = sha1($key);
}
......@@ -353,10 +343,8 @@ class SQL extends Store
* @param int|null $expire The expiration time (unix timestamp), or null if it never expires.
* @return void
*/
public function set($type, $key, $value, $expire = null)
public function set(string $type, string $key, $value, ?int $expire = null): void
{
Assert::string($type);
Assert::string($key);
Assert::nullOrGreaterThan($expire, 2592000);
if (rand(0, 1000) < 10) {
......@@ -392,11 +380,8 @@ class SQL extends Store
* @param string $key The key to delete.
* @return void
*/
public function delete($type, $key)
public function delete(string $type, string $key): void
{
Assert::string($type);
Assert::string($key);
if (strlen($key) > 50) {
$key = sha1($key);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment