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 ...@@ -40,11 +40,8 @@ class Memcache extends Store
* @param string $key The key. * @param string $key The key.
* @return mixed|null The value. * @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); return \SimpleSAML\Memcache::get($this->prefix . '.' . $type . '.' . $key);
} }
...@@ -58,10 +55,8 @@ class Memcache extends Store ...@@ -58,10 +55,8 @@ class Memcache extends Store
* @param int|null $expire The expiration time (unix timestamp), or NULL if it never expires. * @param int|null $expire The expiration time (unix timestamp), or NULL if it never expires.
* @return void * @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); Assert::nullOrGreaterThan($expire, 2592000);
if ($expire === null) { if ($expire === null) {
...@@ -79,11 +74,8 @@ class Memcache extends Store ...@@ -79,11 +74,8 @@ class Memcache extends Store
* @param string $key The key. * @param string $key The key.
* @return void * @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); \SimpleSAML\Memcache::delete($this->prefix . '.' . $type . '.' . $key);
} }
} }
...@@ -77,11 +77,8 @@ class Redis extends Store ...@@ -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. * @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}"); $result = $this->redis->get("{$type}.{$key}");
if ($result === false || $result === null) { if ($result === false || $result === null) {
...@@ -101,10 +98,8 @@ class Redis extends Store ...@@ -101,10 +98,8 @@ class Redis extends Store
* @param int|null $expire The expiration time (unix timestamp), or null if it never expires. * @param int|null $expire The expiration time (unix timestamp), or null if it never expires.
* @return void * @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); Assert::nullOrGreaterThan($expire, 2592000);
$serialized = serialize($value); $serialized = serialize($value);
...@@ -125,11 +120,8 @@ class Redis extends Store ...@@ -125,11 +120,8 @@ class Redis extends Store
* @param string $key The key to delete. * @param string $key The key to delete.
* @return void * @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}"); $this->redis->del("{$type}.{$key}");
} }
} }
...@@ -84,7 +84,7 @@ class SQL extends Store ...@@ -84,7 +84,7 @@ class SQL extends Store
* Initialize the table-version table. * Initialize the table-version table.
* @return void * @return void
*/ */
private function initTableVersionTable() private function initTableVersionTable(): void
{ {
$this->tableVersions = []; $this->tableVersions = [];
...@@ -108,7 +108,7 @@ class SQL extends Store ...@@ -108,7 +108,7 @@ class SQL extends Store
* Initialize key-value table. * Initialize key-value table.
* @return void * @return void
*/ */
private function initKVTable() private function initKVTable(): void
{ {
$current_version = $this->getTableVersion('kvstore'); $current_version = $this->getTableVersion('kvstore');
...@@ -188,10 +188,8 @@ class SQL extends Store ...@@ -188,10 +188,8 @@ class SQL extends Store
* *
* @return int The table version, or 0 if the table doesn't exist. * @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])) { if (!isset($this->tableVersions[$name])) {
return 0; return 0;
} }
...@@ -207,11 +205,8 @@ class SQL extends Store ...@@ -207,11 +205,8 @@ class SQL extends Store
* @param int $version Table version. * @param int $version Table version.
* @return void * @return void
*/ */
public function setTableVersion($name, $version) public function setTableVersion(string $name, int $version): void
{ {
Assert::string($name);
Assert::integer($version);
$this->insertOrUpdate( $this->insertOrUpdate(
$this->prefix . '_tableVersion', $this->prefix . '_tableVersion',
['_name'], ['_name'],
...@@ -231,10 +226,8 @@ class SQL extends Store ...@@ -231,10 +226,8 @@ class SQL extends Store
* @param array $data Associative array with columns. * @param array $data Associative array with columns.
* @return void * @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)) . ')'; $colNames = '(' . implode(', ', array_keys($data)) . ')';
$values = 'VALUES(:' . implode(', :', array_keys($data)) . ')'; $values = 'VALUES(:' . implode(', :', array_keys($data)) . ')';
...@@ -289,7 +282,7 @@ class SQL extends Store ...@@ -289,7 +282,7 @@ class SQL extends Store
* Clean the key-value table of expired entries. * Clean the key-value table of expired entries.
* @return void * @return void
*/ */
private function cleanKVStore() private function cleanKVStore(): void
{ {
Logger::debug('store.sql: Cleaning key-value store.'); Logger::debug('store.sql: Cleaning key-value store.');
...@@ -309,11 +302,8 @@ class SQL extends 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. * @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) { if (strlen($key) > 50) {
$key = sha1($key); $key = sha1($key);
} }
...@@ -353,10 +343,8 @@ class SQL extends Store ...@@ -353,10 +343,8 @@ class SQL extends Store
* @param int|null $expire The expiration time (unix timestamp), or null if it never expires. * @param int|null $expire The expiration time (unix timestamp), or null if it never expires.
* @return void * @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); Assert::nullOrGreaterThan($expire, 2592000);
if (rand(0, 1000) < 10) { if (rand(0, 1000) < 10) {
...@@ -392,11 +380,8 @@ class SQL extends Store ...@@ -392,11 +380,8 @@ class SQL extends Store
* @param string $key The key to delete. * @param string $key The key to delete.
* @return void * @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) { if (strlen($key) > 50) {
$key = sha1($key); $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