- added more type-hints
- added missing documentation
This commit is contained in:
Roland Häder 2022-06-18 18:21:05 +02:00
parent 94eb426151
commit 9691bb06fb
No known key found for this signature in database
GPG key ID: C82EDE5DDFA0BA77
2 changed files with 209 additions and 184 deletions

View file

@ -40,16 +40,16 @@ class OpenWebAuthToken
* @return boolean
* @throws \Exception
*/
public static function create($type, $uid, $token, $meta)
public static function create(string $type, uid $uid, string $token, string $meta)
{
$fields = [
"type" => $type,
"uid" => $uid,
"token" => $token,
"meta" => $meta,
"created" => DateTimeFormat::utcNow()
'type' => $type,
'uid' => $uid,
'token' => $token,
'meta' => $meta,
'created' => DateTimeFormat::utcNow()
];
return DBA::insert("openwebauth-token", $fields);
return DBA::insert('openwebauth-token', $fields);
}
/**
@ -62,15 +62,15 @@ class OpenWebAuthToken
* @return string|boolean The meta enry or false if not found.
* @throws \Exception
*/
public static function getMeta($type, $uid, $token)
public static function getMeta(string $type, int $uid, string $token)
{
$condition = ["type" => $type, "uid" => $uid, "token" => $token];
$condition = ['type' => $type, 'uid' => $uid, 'token' => $token];
$entry = DBA::selectFirst("openwebauth-token", ["id", "meta"], $condition);
$entry = DBA::selectFirst('openwebauth-token', ['id', 'meta'], $condition);
if (DBA::isResult($entry)) {
DBA::delete("openwebauth-token", ["id" => $entry["id"]]);
DBA::delete('openwebauth-token', ['id' => $entry['id']]);
return $entry["meta"];
return $entry['meta'];
}
return false;
}
@ -82,10 +82,10 @@ class OpenWebAuthToken
* @param string $interval SQL compatible time interval
* @throws \Exception
*/
public static function purge($type, $interval)
public static function purge(string $type, string $interval)
{
$condition = ["`type` = ? AND `created` < ?", $type, DateTimeFormat::utcNow() . " - INTERVAL " . $interval];
DBA::delete("openwebauth-token", $condition);
$condition = ['`type` = ? AND `created` < ?', $type, DateTimeFormat::utcNow() . ' - INTERVAL ' . $interval];
DBA::delete('openwebauth-token', $condition);
}
}