From 008ffc8ccd9d8101bc22a40fa2e849e80d5c82b8 Mon Sep 17 00:00:00 2001 From: Mike Colagrosso Date: Sat, 29 Jun 2024 13:47:54 -0600 Subject: [PATCH] Fix PHPStan errors --- lib/HttpInput.php | 2 +- lib/Session.php | 3 ++- www/ebooks/download.php | 3 ++- www/ebooks/ebook.php | 1 + www/settings/post.php | 6 ++++-- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/HttpInput.php b/lib/HttpInput.php index d4347a30..aa4456c9 100644 --- a/lib/HttpInput.php +++ b/lib/HttpInput.php @@ -184,7 +184,7 @@ class HttpInput{ return $var; case HttpVariableType::Integer: // Can't use ctype_digit because we may want negative integers - if(is_numeric($var) && mb_strpos($var, '.') === false){ + if(is_numeric($var) && mb_strpos(strval($var), '.') === false){ try{ return intval($var); } diff --git a/lib/Session.php b/lib/Session.php index b3b99ba2..4ad00afc 100644 --- a/lib/Session.php +++ b/lib/Session.php @@ -98,7 +98,8 @@ class Session{ } public static function SetSessionCookie(string $sessionId): void{ - setcookie('sessionid', $sessionId, ['expires' => (new DateTimeImmutable('+1 week'))->format('U'), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => false, 'samesite' => 'Lax']); // Expires in two weeks + /** @throws void */ + setcookie('sessionid', $sessionId, ['expires' => intval((new DateTimeImmutable('+1 week'))->format('U')), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => false, 'samesite' => 'Lax']); // Expires in two weeks } /** diff --git a/www/ebooks/download.php b/www/ebooks/download.php index 0f42d206..cd8d6570 100644 --- a/www/ebooks/download.php +++ b/www/ebooks/download.php @@ -1,4 +1,5 @@ (new DateTimeImmutable('+2 week'))->format('U'), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => false, 'samesite' => 'Lax']); + setcookie('download-count', (string)$downloadCount, ['expires' => intval((new DateTimeImmutable('+2 week'))->format('U')), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => false, 'samesite' => 'Lax']); } catch(Exceptions\InvalidFileException | Exceptions\EbookNotFoundException){ Template::Emit404(); diff --git a/www/ebooks/ebook.php b/www/ebooks/ebook.php index e42bff09..cfab46ae 100644 --- a/www/ebooks/ebook.php +++ b/www/ebooks/ebook.php @@ -1,6 +1,7 @@ (new DateTimeImmutable('+1 month'))->format('U'), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']); + setcookie('hide-donation-alert', $hideDonationAlert ? 'true' : 'false', ['expires' => intval((new DateTimeImmutable('+1 month'))->format('U')), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']); } if($colorScheme !== null){ @@ -16,7 +18,7 @@ if($colorScheme !== null){ setcookie('color-scheme', '', ['expires' => 0, 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']); } else{ - setcookie('color-scheme', $colorScheme, ['expires' => (new DateTimeImmutable('+1 year'))->format('U'), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']); + setcookie('color-scheme', $colorScheme, ['expires' => intval((new DateTimeImmutable('+1 year'))->format('U')), 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']); } }