From bd4b8d8944ef45069f6b983288a372ca79423ff4 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Wed, 21 Jun 2023 11:01:43 -0500 Subject: [PATCH] Some type check fixes --- lib/Ebook.php | 3 ++- lib/NewsletterSubscription.php | 2 +- lib/Payment.php | 2 +- lib/Session.php | 1 + lib/User.php | 2 +- www/webhooks/postmark.php | 1 - 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/Ebook.php b/lib/Ebook.php index dbcfb6b3..682d7764 100644 --- a/lib/Ebook.php +++ b/lib/Ebook.php @@ -6,6 +6,7 @@ use function Safe\json_encode; use function Safe\glob; use function Safe\preg_match; use function Safe\preg_replace; +use function Safe\sprintf; use function Safe\substr; class Ebook{ @@ -108,7 +109,7 @@ class Ebook{ // emits a warning. So, just silence the warning. $bytes = @filesize($this->WwwFilesystemPath . '/text/single-page.xhtml'); $sizes = 'BKMGTP'; - $factor = floor((strlen($bytes) - 1) / 3); + $factor = intval(floor((strlen((string)$bytes) - 1) / 3)); $this->TextSinglePageSizeNumber = sprintf('%.1f', $bytes / pow(1024, $factor)); $this->TextSinglePageSizeUnit = $sizes[$factor] ?? ''; $this->TextSinglePageUrl = $this->Url . '/text/single-page'; diff --git a/lib/NewsletterSubscription.php b/lib/NewsletterSubscription.php index f1ea4810..e56cec14 100644 --- a/lib/NewsletterSubscription.php +++ b/lib/NewsletterSubscription.php @@ -57,7 +57,7 @@ class NewsletterSubscription extends PropertiesBase{ ', [$this->User->UserId, false, $this->IsSubscribedToNewsletter, $this->IsSubscribedToSummary, $this->Created]); } catch(PDOException $ex){ - if($ex->errorInfo[1] == 1062){ + if(($ex->errorInfo[1] ?? 0) == 1062){ // Duplicate unique key; email already in use throw new Exceptions\NewsletterSubscriptionExistsException(); } diff --git a/lib/Payment.php b/lib/Payment.php index 500d5f5a..cf14dda0 100644 --- a/lib/Payment.php +++ b/lib/Payment.php @@ -63,7 +63,7 @@ class Payment extends PropertiesBase{ ', [$this->UserId, $this->Created, $this->ChannelId, $this->TransactionId, $this->Amount, $this->Fee, $this->IsRecurring, $this->IsMatchingDonation]); } catch(PDOException $ex){ - if($ex->errorInfo[1] == 1062){ + if(($ex->errorInfo[1] ?? 0) == 1062){ // Duplicate unique key; transction ID already exists throw new Exceptions\PaymentExistsException(); } diff --git a/lib/Session.php b/lib/Session.php index 434c21d4..962f969d 100644 --- a/lib/Session.php +++ b/lib/Session.php @@ -1,6 +1,7 @@ Email, $this->Name, $this->Uuid, $this->Created]); } catch(PDOException $ex){ - if($ex->errorInfo[1] == 1062){ + if(($ex->errorInfo[1] ?? 0) == 1062){ // Duplicate unique key; email already in use throw new Exceptions\UserExistsException(); } diff --git a/www/webhooks/postmark.php b/www/webhooks/postmark.php index c1c978e4..3883f815 100644 --- a/www/webhooks/postmark.php +++ b/www/webhooks/postmark.php @@ -65,7 +65,6 @@ try{ curl_setopt($handle, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($handle, CURLOPT_POSTFIELDS, '{"Suppressions": [{"EmailAddress": "' . $email . '"}]}'); curl_exec($handle); - curl_close($handle); } elseif($post->RecordType == 'SubscriptionChange' && $post->SuppressionReason === null){ $log->Write('Event type: suppression deletion.');