Fix PHPStan errors

This commit is contained in:
Mike Colagrosso 2024-06-29 13:47:54 -06:00 committed by Alex Cabal
parent 6af2717773
commit 008ffc8ccd
5 changed files with 10 additions and 5 deletions

View file

@ -184,7 +184,7 @@ class HttpInput{
return $var; return $var;
case HttpVariableType::Integer: case HttpVariableType::Integer:
// Can't use ctype_digit because we may want negative integers // 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{ try{
return intval($var); return intval($var);
} }

View file

@ -98,7 +98,8 @@ class Session{
} }
public static function SetSessionCookie(string $sessionId): void{ 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
} }
/** /**

View file

@ -1,4 +1,5 @@
<? <?
use Safe\DateTimeImmutable;
use function Safe\apcu_fetch; use function Safe\apcu_fetch;
// If the user is not logged in, or has less than some amount of downloads, show a thank-you page // If the user is not logged in, or has less than some amount of downloads, show a thank-you page
@ -60,7 +61,7 @@ try{
// Increment local download count, expires in 2 weeks // Increment local download count, expires in 2 weeks
$downloadCount++; $downloadCount++;
setcookie('download-count', (string)$downloadCount, ['expires' => (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){ catch(Exceptions\InvalidFileException | Exceptions\EbookNotFoundException){
Template::Emit404(); Template::Emit404();

View file

@ -1,6 +1,7 @@
<? <?
// See https://developers.google.com/search/docs/data-types/book for RDFa metadata details // See https://developers.google.com/search/docs/data-types/book for RDFa metadata details
use Safe\DateTimeImmutable;
use function Safe\preg_match; use function Safe\preg_match;
use function Safe\preg_replace; use function Safe\preg_replace;
use function Safe\apcu_fetch; use function Safe\apcu_fetch;

View file

@ -1,9 +1,11 @@
<? <?
use Safe\DateTimeImmutable;
$hideDonationAlert = HttpInput::Bool(POST, 'hide-donation-alert'); $hideDonationAlert = HttpInput::Bool(POST, 'hide-donation-alert');
$colorScheme = HttpInput::Str(POST, 'color-scheme'); $colorScheme = HttpInput::Str(POST, 'color-scheme');
if($hideDonationAlert !== null){ if($hideDonationAlert !== null){
setcookie('hide-donation-alert', $hideDonationAlert ? 'true' : 'false', ['expires' => (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){ 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']); setcookie('color-scheme', '', ['expires' => 0, 'path' => '/', 'domain' => SITE_DOMAIN, 'secure' => true, 'httponly' => true, 'samesite' => 'Lax']);
} }
else{ 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']);
} }
} }