From bf2bb875ab09c1cb51b7ac0a7bb29a79770e435f Mon Sep 17 00:00:00 2001 From: wn_ Date: Thu, 11 Nov 2021 15:57:03 +0000 Subject: [PATCH] Address PHPStan warnings in 'include/sessions.php'. --- include/sessions.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/include/sessions.php b/include/sessions.php index 26f4e0bca..48afd0a8b 100644 --- a/include/sessions.php +++ b/include/sessions.php @@ -1,9 +1,9 @@ prepare("SELECT data FROM ttrss_sessions WHERE id=?"); @@ -84,7 +84,7 @@ require_once "autoload.php"; } - function ttrss_write ($id, $data) { + function ttrss_write(string $id, string $data): bool { global $session_expire; $data = base64_encode($data); @@ -105,18 +105,18 @@ require_once "autoload.php"; return true; } - function ttrss_close () { + function ttrss_close(): bool { return true; } - function ttrss_destroy($id) { + function ttrss_destroy(string $id): bool { $sth = \Db::pdo()->prepare("DELETE FROM ttrss_sessions WHERE id = ?"); $sth->execute([$id]); return true; } - function ttrss_gc ($expire) { + function ttrss_gc(int $lifetime): bool { \Db::pdo()->query("DELETE FROM ttrss_sessions WHERE expire < " . time()); return true; @@ -126,7 +126,10 @@ require_once "autoload.php"; session_set_save_handler('\Sessions\ttrss_open', '\Sessions\ttrss_close', '\Sessions\ttrss_read', '\Sessions\ttrss_write', '\Sessions\ttrss_destroy', - '\Sessions\ttrss_gc'); + '\Sessions\ttrss_gc'); // @phpstan-ignore-line + // PHPStan complains about '\Sessions\ttrss_gc' if its $lifetime param isn't marked as string, + // but the docs say it's an int. If it is actually a string it'll get coerced to an int. + register_shutdown_function('session_write_close'); if (!defined('NO_SESSION_AUTOSTART')) {