Remove unused exception variables, now that this is possible with PHP8

This commit is contained in:
Alex Cabal 2023-06-06 21:00:12 -05:00
parent fe16cb3b21
commit 8127f0c7e2
36 changed files with 60 additions and 63 deletions

View file

@ -83,7 +83,7 @@ class AtomFeed extends Feed{
$oldEntries[] = $obj; $oldEntries[] = $obj;
} }
} }
catch(Exception $ex){ catch(Exception){
// Invalid XML // Invalid XML
return true; return true;
} }

View file

@ -41,7 +41,7 @@ if($GLOBALS['User'] === null){
$session->Create($httpBasicAuthLogin); $session->Create($httpBasicAuthLogin);
$GLOBALS['User'] = $session->User; $GLOBALS['User'] = $session->User;
} }
catch(Exception $ex){ catch(Exception){
// Do nothing // Do nothing
} }
} }

View file

@ -113,7 +113,7 @@ class Ebook{
$this->TextSinglePageSizeUnit = $sizes[$factor] ?? ''; $this->TextSinglePageSizeUnit = $sizes[$factor] ?? '';
$this->TextSinglePageUrl = $this->Url . '/text/single-page'; $this->TextSinglePageUrl = $this->Url . '/text/single-page';
} }
catch(Exception $ex){ catch(Exception){
// Single page file doesn't exist, just pass // Single page file doesn't exist, just pass
} }

View file

@ -100,7 +100,7 @@ class HttpInput{
try{ try{
return intval($var); return intval($var);
} }
catch(\Exception $ex){ catch(Exception){
return $default; return $default;
} }
} }
@ -117,7 +117,7 @@ class HttpInput{
try{ try{
return floatval($var); return floatval($var);
} }
catch(\Exception $ex){ catch(Exception){
return $default; return $default;
} }
} }

View file

@ -132,7 +132,7 @@ class Library{
try{ try{
return apcu_fetch('tag-' . $tag) ?? []; return apcu_fetch('tag-' . $tag) ?? [];
} }
catch(Safe\Exceptions\ApcuException $ex){ catch(Safe\Exceptions\ApcuException){
return []; return [];
} }
} }
@ -168,12 +168,12 @@ class Library{
try{ try{
$results = apcu_fetch($variable); $results = apcu_fetch($variable);
} }
catch(Safe\Exceptions\ApcuException $ex){ catch(Safe\Exceptions\ApcuException){
Library::RebuildCache(); Library::RebuildCache();
try{ try{
$results = apcu_fetch($variable); $results = apcu_fetch($variable);
} }
catch(Safe\Exceptions\ApcuException $ex){ catch(Safe\Exceptions\ApcuException){
// We can get here if the cache is currently rebuilding from a different process. // We can get here if the cache is currently rebuilding from a different process.
// Nothing we can do but wait, so wait 20 seconds before retrying // Nothing we can do but wait, so wait 20 seconds before retrying
sleep(20); sleep(20);
@ -181,7 +181,7 @@ class Library{
try{ try{
$results = apcu_fetch($variable); $results = apcu_fetch($variable);
} }
catch(Safe\Exceptions\ApcuException $ex){ catch(Safe\Exceptions\ApcuException){
// Cache STILL rebuilding... give up silently for now // Cache STILL rebuilding... give up silently for now
} }
} }
@ -224,7 +224,7 @@ class Library{
$ebooks[] = new Ebook($ebookWwwFilesystemPath); $ebooks[] = new Ebook($ebookWwwFilesystemPath);
} }
catch(\Exception $ex){ catch(\Exception){
// An error in a book isn't fatal; just carry on. // An error in a book isn't fatal; just carry on.
} }
} }
@ -443,7 +443,7 @@ class Library{
$val = apcu_fetch($lockVar); $val = apcu_fetch($lockVar);
return; return;
} }
catch(Safe\Exceptions\ApcuException $ex){ catch(Safe\Exceptions\ApcuException){
apcu_store($lockVar, true); apcu_store($lockVar, true);
} }
@ -508,7 +508,7 @@ class Library{
$authors[$authorPath][] = $ebook; $authors[$authorPath][] = $ebook;
} }
catch(\Exception $ex){ catch(\Exception){
// An error in a book isn't fatal; just carry on. // An error in a book isn't fatal; just carry on.
} }
} }

View file

@ -29,7 +29,7 @@ class Log{
try{ try{
$fp = fopen($this->LogFilePath, 'a+'); $fp = fopen($this->LogFilePath, 'a+');
} }
catch(\Exception $ex){ catch(Exception $ex){
self::WriteErrorLogEntry('Couldn\'t open log file: ' . $this->LogFilePath . '. Exception: ' . vds($ex)); self::WriteErrorLogEntry('Couldn\'t open log file: ' . $this->LogFilePath . '. Exception: ' . vds($ex));
return; return;
} }

View file

@ -19,7 +19,7 @@ class Manual{
return null; return null;
} }
} }
catch(\Exception $ex){ catch(Exception){
return null; return null;
} }
} }

View file

@ -38,7 +38,7 @@ class NewsletterSubscription extends PropertiesBase{
try{ try{
$this->User = User::GetByEmail($this->User->Email); $this->User = User::GetByEmail($this->User->Email);
} }
catch(Exceptions\InvalidUserException $ex){ catch(Exceptions\InvalidUserException){
// User doesn't exist, create the user // User doesn't exist, create the user
$this->User->Create(); $this->User->Create();
} }

View file

@ -31,7 +31,7 @@ class OpdsNavigationFeed extends OpdsFeed{
} }
} }
} }
catch(Exception $ex){ catch(Exception){
// XML parsing failure // XML parsing failure
} }
} }

View file

@ -40,7 +40,7 @@ class Payment extends PropertiesBase{
where UserId = ? where UserId = ?
', [$this->User->Name, $this->User->UserId]); ', [$this->User->Name, $this->User->UserId]);
} }
catch(Exceptions\InvalidUserException $ex){ catch(Exceptions\InvalidUserException){
// User doesn't exist, create it now // User doesn't exist, create it now
$this->User->Create(); $this->User->Create();
} }

View file

@ -61,7 +61,7 @@ class PollVote extends PropertiesBase{
$vote = PollVote::Get($this->PollItem->Poll->UrlName, $this->UserId); $vote = PollVote::Get($this->PollItem->Poll->UrlName, $this->UserId);
$error->Add(new Exceptions\PollVoteExistsException($vote)); $error->Add(new Exceptions\PollVoteExistsException($vote));
} }
catch(Exceptions\InvalidPollVoteException $ex){ catch(Exceptions\InvalidPollVoteException){
// User hasn't voted yet, carry on // User hasn't voted yet, carry on
} }
@ -81,7 +81,7 @@ class PollVote extends PropertiesBase{
$this->User = User::GetByEmail($email); $this->User = User::GetByEmail($email);
$this->UserId = $this->User->UserId; $this->UserId = $this->User->UserId;
} }
catch(Exceptions\InvalidUserException $ex){ catch(Exceptions\InvalidUserException){
// Can't validate patron email - do nothing for now, // Can't validate patron email - do nothing for now,
// this will be caught later when we validate the vote during creation. // this will be caught later when we validate the vote during creation.
// Save the email in the User object in case we want it later, // Save the email in the User object in case we want it later,

View file

@ -78,7 +78,7 @@ class RssFeed extends Feed{
$oldEntries[] = $obj; $oldEntries[] = $obj;
} }
} }
catch(Exception $ex){ catch(Exception){
// Invalid XML // Invalid XML
return true; return true;
} }

View file

@ -105,7 +105,7 @@ try{
try{ try{
$toggleButton = $driver->wait(20, 250)->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::xpath('//button[contains(@class, "button-toggle")]'))); $toggleButton = $driver->wait(20, 250)->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::xpath('//button[contains(@class, "button-toggle")]')));
} }
catch(Exception $ex){ catch(Exception){
$log->Write('Error: Couldn\'t find donation.'); $log->Write('Error: Couldn\'t find donation.');
continue; continue;
} }
@ -147,7 +147,7 @@ try{
$payment->User = null; $payment->User = null;
} }
} }
catch(Exception $ex){ catch(Exception){
// Anonymous donations don't have these elements present and will throw an exception // Anonymous donations don't have these elements present and will throw an exception
$payment->User = null; $payment->User = null;
} }
@ -172,7 +172,7 @@ try{
try{ try{
$payment->Create(); $payment->Create();
} }
catch(Exceptions\PaymentExistsException $ex){ catch(Exceptions\PaymentExistsException){
// Payment already exists, just continue // Payment already exists, just continue
$log->Write('Donation already in database.'); $log->Write('Donation already in database.');
continue; continue;
@ -217,7 +217,7 @@ try{
try{ try{
$patron->AlternateName = trim($detailsRow->findElement(WebDriverBy::xpath('//td[preceding-sibling::td[normalize-space(.) = "Attribution Text"]]'))->getText()); $patron->AlternateName = trim($detailsRow->findElement(WebDriverBy::xpath('//td[preceding-sibling::td[normalize-space(.) = "Attribution Text"]]'))->getText());
} }
catch(Exception $ex){ catch(Exception){
} }
$log->Write('Adding donor as patron ...'); $log->Write('Adding donor as patron ...');

View file

@ -20,7 +20,7 @@ $collection = [];
try{ try{
$collection = apcu_fetch('bulk-downloads-' . $class); $collection = apcu_fetch('bulk-downloads-' . $class);
} }
catch(Safe\Exceptions\ApcuException $ex){ catch(Safe\Exceptions\ApcuException){
$result = Library::RebuildBulkDownloadsCache(); $result = Library::RebuildBulkDownloadsCache();
$collection = $result[$class]; $collection = $result[$class];
} }

View file

@ -32,7 +32,7 @@ try{
header('Content-Disposition: attachment; filename="' . basename($path) . '"'); header('Content-Disposition: attachment; filename="' . basename($path) . '"');
exit(); exit();
} }
catch(Exceptions\LoginRequiredException $ex){ catch(Exceptions\LoginRequiredException){
if(isset($_SERVER['HTTP_REFERER'])){ if(isset($_SERVER['HTTP_REFERER'])){
Template::RedirectToLogin(true, $_SERVER['HTTP_REFERER']); Template::RedirectToLogin(true, $_SERVER['HTTP_REFERER']);
} }
@ -48,10 +48,10 @@ catch(Exceptions\LoginRequiredException $ex){
} }
} }
} }
catch(Exceptions\InvalidPermissionsException $ex){ catch(Exceptions\InvalidPermissionsException){
http_response_code(403); http_response_code(403);
} }
catch(Exceptions\InvalidFileException $ex){ catch(Exceptions\InvalidFileException){
Template::Emit404(); Template::Emit404();
} }

View file

@ -21,7 +21,7 @@ try{
try{ try{
$collections = apcu_fetch('bulk-downloads-collections'); $collections = apcu_fetch('bulk-downloads-collections');
} }
catch(Safe\Exceptions\ApcuException $ex){ catch(Safe\Exceptions\ApcuException){
$result = Library::RebuildBulkDownloadsCache(); $result = Library::RebuildBulkDownloadsCache();
$collections = $result['collections']; $collections = $result['collections'];
} }
@ -45,7 +45,7 @@ try{
try{ try{
$collections = apcu_fetch('bulk-downloads-authors'); $collections = apcu_fetch('bulk-downloads-authors');
} }
catch(Safe\Exceptions\ApcuException $ex){ catch(Safe\Exceptions\ApcuException){
$result = Library::RebuildBulkDownloadsCache(); $result = Library::RebuildBulkDownloadsCache();
$collections = $result['authors']; $collections = $result['authors'];
} }
@ -62,13 +62,10 @@ try{
} }
} }
} }
catch(Exceptions\InvalidUserException $ex){ catch(Exceptions\InvalidAuthorException){
$exception = new Exceptions\InvalidPatronException();
}
catch(Exceptions\InvalidAuthorException $ex){
Template::Emit404(); Template::Emit404();
} }
catch(Exceptions\InvalidCollectionException $ex){ catch(Exceptions\InvalidCollectionException){
Template::Emit404(); Template::Emit404();
} }

View file

@ -23,7 +23,7 @@ try{
$author = strip_tags($ebooks[0]->AuthorsHtml); $author = strip_tags($ebooks[0]->AuthorsHtml);
$authorUrl = Formatter::ToPlainText($ebooks[0]->AuthorsUrl); $authorUrl = Formatter::ToPlainText($ebooks[0]->AuthorsUrl);
} }
catch(Exceptions\InvalidAuthorException $ex){ catch(Exceptions\InvalidAuthorException){
Template::Emit404(); Template::Emit404();
} }
?><?= Template::Header(['title' => 'Ebooks by ' . $author, 'feedUrl' => str_replace('/ebooks/', '/authors/', $authorUrl), 'feedTitle' => 'Standard Ebooks - Ebooks by ' . $author, 'highlight' => 'ebooks', 'description' => 'All of the Standard Ebooks ebooks by ' . $author]) ?> ?><?= Template::Header(['title' => 'Ebooks by ' . $author, 'feedUrl' => str_replace('/ebooks/', '/authors/', $authorUrl), 'feedTitle' => 'Standard Ebooks - Ebooks by ' . $author, 'highlight' => 'ebooks', 'description' => 'All of the Standard Ebooks ebooks by ' . $author]) ?>

View file

@ -43,7 +43,7 @@ try{
try{ try{
$ebook = apcu_fetch('ebook-' . $wwwFilesystemPath); $ebook = apcu_fetch('ebook-' . $wwwFilesystemPath);
} }
catch(Safe\Exceptions\ApcuException $ex){ catch(Safe\Exceptions\ApcuException){
$ebook = new Ebook($wwwFilesystemPath); $ebook = new Ebook($wwwFilesystemPath);
} }
@ -106,7 +106,7 @@ catch(Exceptions\SeeOtherEbookException $ex){
header('Location: ' . $ex->Url); header('Location: ' . $ex->Url);
exit(); exit();
} }
catch(Exceptions\InvalidEbookException $ex){ catch(Exceptions\InvalidEbookException){
Template::Emit404(); Template::Emit404();
} }
?><?= Template::Header(['title' => strip_tags($ebook->TitleWithCreditsHtml) . ' - Free ebook download', 'ogType' => 'book', 'coverUrl' => $ebook->DistCoverUrl, 'highlight' => 'ebooks', 'description' => 'Free epub ebook download of the Standard Ebooks edition of ' . $ebook->Title . ': ' . $ebook->Description]) ?> ?><?= Template::Header(['title' => strip_tags($ebook->TitleWithCreditsHtml) . ' - Free ebook download', 'ogType' => 'book', 'coverUrl' => $ebook->DistCoverUrl, 'highlight' => 'ebooks', 'description' => 'Free epub ebook download of the Standard Ebooks edition of ' . $ebook->Title . ': ' . $ebook->Description]) ?>

View file

@ -120,7 +120,7 @@ try{
$feedTitle = 'Standard Ebooks - Ebooks in the ' . Formatter::ToPlainText($collectionName) . ' ' . $collectionType; $feedTitle = 'Standard Ebooks - Ebooks in the ' . Formatter::ToPlainText($collectionName) . ' ' . $collectionType;
} }
} }
catch(Exceptions\InvalidCollectionException $ex){ catch(Exceptions\InvalidCollectionException){
Template::Emit404(); Template::Emit404();
} }
?><?= Template::Header(['title' => $pageTitle, 'feedUrl' => $feedUrl, 'feedTitle' => $feedTitle, 'highlight' => 'ebooks', 'description' => $pageDescription]) ?> ?><?= Template::Header(['title' => $pageTitle, 'feedUrl' => $feedUrl, 'feedTitle' => $feedTitle, 'highlight' => 'ebooks', 'description' => $pageDescription]) ?>

View file

@ -11,7 +11,7 @@ try{
$ebooks = Library::Search($query); $ebooks = Library::Search($query);
} }
} }
catch(\Exception $ex){ catch(\Exception){
http_response_code(500); http_response_code(500);
include(WEB_ROOT . '/404.php'); include(WEB_ROOT . '/404.php');
exit(); exit();

View file

@ -29,7 +29,7 @@ if($type === 'atom'){
try{ try{
$feeds = apcu_fetch('feeds-index-' . $type . '-' . $class); $feeds = apcu_fetch('feeds-index-' . $type . '-' . $class);
} }
catch(Safe\Exceptions\ApcuException $ex){ catch(Safe\Exceptions\ApcuException){
$feeds = Library::RebuildFeedsCache($type, $class); $feeds = Library::RebuildFeedsCache($type, $class);
} }
?><?= Template::Header(['title' => $ucType . ' Ebook Feeds by ' . $ucTitle, 'description' => 'A list of available ' . $ucType . ' feeds of Standard Ebooks ebooks by ' . $lcTitle . '.']) ?> ?><?= Template::Header(['title' => $ucType . ' Ebook Feeds by ' . $ucTitle, 'description' => 'A list of available ' . $ucType . ' feeds of Standard Ebooks ebooks by ' . $lcTitle . '.']) ?>

View file

@ -70,14 +70,14 @@ try{
exit(); exit();
} }
catch(Exceptions\LoginRequiredException $ex){ catch(Exceptions\LoginRequiredException){
header('WWW-Authenticate: Basic realm="Enter your Patrons Circle email address and leave the password empty."'); header('WWW-Authenticate: Basic realm="Enter your Patrons Circle email address and leave the password empty."');
http_response_code(401); http_response_code(401);
} }
catch(Exceptions\InvalidPermissionsException $ex){ catch(Exceptions\InvalidPermissionsException){
http_response_code(403); http_response_code(403);
} }
catch(Exceptions\InvalidFileException $ex){ catch(Exceptions\InvalidFileException){
Template::Emit404(); Template::Emit404();
} }

View file

@ -48,7 +48,7 @@ try{
$feedUrl = '/' . $name . '/' . $target; $feedUrl = '/' . $name . '/' . $target;
} }
catch(Exceptions\InvalidCollectionException $ex){ catch(Exceptions\InvalidCollectionException){
Template::Emit404(); Template::Emit404();
} }
?><?= Template::Header(['title' => $title, 'feedTitle' => $feedTitle, 'feedUrl' => $feedUrl, 'description' => $description]) ?> ?><?= Template::Header(['title' => $title, 'feedTitle' => $feedTitle, 'feedUrl' => $feedUrl, 'description' => $description]) ?>

View file

@ -11,7 +11,7 @@ try{
$ebooks = Library::Search($query); $ebooks = Library::Search($query);
} }
} }
catch(\Exception $ex){ catch(\Exception){
http_response_code(500); http_response_code(500);
exit(); exit();
} }

View file

@ -11,7 +11,7 @@ try{
$ebooks = Library::Search($query); $ebooks = Library::Search($query);
} }
} }
catch(\Exception $ex){ catch(\Exception){
http_response_code(500); http_response_code(500);
include(WEB_ROOT . '/404.php'); include(WEB_ROOT . '/404.php');
exit(); exit();

View file

@ -16,6 +16,6 @@ try{
http_response_code(303); http_response_code(303);
header('Location: ' . $subscription->Url); header('Location: ' . $subscription->Url);
} }
catch(Exceptions\InvalidNewsletterSubscriptionException $ex){ catch(Exceptions\InvalidNewsletterSubscriptionException){
Template::Emit404(); Template::Emit404();
} }

View file

@ -18,11 +18,11 @@ try{
exit(); exit();
} }
} }
catch(Exceptions\InvalidRequestException $ex){ catch(Exceptions\InvalidRequestException){
http_response_code(405); http_response_code(405);
exit(); exit();
} }
catch(Exceptions\InvalidNewsletterSubscriptionException $ex){ catch(Exceptions\InvalidNewsletterSubscriptionException){
if($requestType == WEB){ if($requestType == WEB){
Template::Emit404(); Template::Emit404();
} }

View file

@ -39,7 +39,7 @@ try{
http_response_code(201); http_response_code(201);
} }
} }
catch(Exceptions\SeException $ex){ catch(Exceptions\SeException){
Template::Emit404(); Template::Emit404();
} }

View file

@ -74,7 +74,7 @@ try{
header('Location: /newsletter/subscriptions/success'); header('Location: /newsletter/subscriptions/success');
} }
} }
catch(Exceptions\NewsletterSubscriptionExistsException $ex){ catch(Exceptions\NewsletterSubscriptionExistsException){
// Subscription exists. // Subscription exists.
if($requestType == WEB){ if($requestType == WEB){
// If we're accessing from the web, update the subscription, // If we're accessing from the web, update the subscription,

View file

@ -20,13 +20,13 @@ try{
try{ try{
PollVote::Get($poll->UrlName, $GLOBALS['User']->UserId); PollVote::Get($poll->UrlName, $GLOBALS['User']->UserId);
} }
catch(Exceptions\SeException $ex){ catch(Exceptions\SeException){
// User has already voted // User has already voted
$canVote = true; $canVote = true;
} }
} }
} }
catch(Exceptions\SeException $ex){ catch(Exceptions\SeException){
Template::Emit404(); Template::Emit404();
} }

View file

@ -17,7 +17,7 @@ try{
session_unset(); session_unset();
} }
} }
catch(Exceptions\SeException $ex){ catch(Exceptions\SeException){
Template::Emit404(); Template::Emit404();
} }

View file

@ -6,7 +6,7 @@ $poll = new Poll();
try{ try{
$poll = Poll::GetByUrlName(HttpInput::Str(GET, 'pollurlname', false)); $poll = Poll::GetByUrlName(HttpInput::Str(GET, 'pollurlname', false));
} }
catch(Exceptions\SeException $ex){ catch(Exceptions\SeException){
Template::Emit404(); Template::Emit404();
} }

View file

@ -29,7 +29,7 @@ try{
// Vote was found, don't allow another vote // Vote was found, don't allow another vote
throw new Exceptions\PollVoteExistsException($vote); throw new Exceptions\PollVoteExistsException($vote);
} }
catch(Exceptions\InvalidPollVoteException $ex){ catch(Exceptions\InvalidPollVoteException){
// Vote was not found, user is OK to vote // Vote was not found, user is OK to vote
} }
@ -38,10 +38,10 @@ try{
session_unset(); session_unset();
} }
} }
catch(Exceptions\LoginRequiredException $ex){ catch(Exceptions\LoginRequiredException){
Template::RedirectToLogin(); Template::RedirectToLogin();
} }
catch(Exceptions\InvalidPollException $ex){ catch(Exceptions\InvalidPollException){
Template::Emit404(); Template::Emit404();
} }
catch(Exceptions\PollVoteExistsException $ex){ catch(Exceptions\PollVoteExistsException $ex){

View file

@ -133,7 +133,7 @@ try{
// "Success, no content" // "Success, no content"
http_response_code(204); http_response_code(204);
} }
catch(Exceptions\InvalidCredentialsException $ex){ catch(Exceptions\InvalidCredentialsException){
// "Forbidden" // "Forbidden"
http_response_code(403); http_response_code(403);
} }
@ -149,7 +149,7 @@ catch(Exceptions\WebhookException $ex){
// "Client error" // "Client error"
http_response_code(400); http_response_code(400);
} }
catch(Exceptions\NoopException $ex){ catch(Exceptions\NoopException){
// We arrive here because a special case required us to take no action for the request, but execution also had to be interrupted. // We arrive here because a special case required us to take no action for the request, but execution also had to be interrupted.
// For example, we received a request for a known repo for which we must ignore requests. // For example, we received a request for a known repo for which we must ignore requests.

View file

@ -79,7 +79,7 @@ try{
// "Success, no content" // "Success, no content"
http_response_code(204); http_response_code(204);
} }
catch(Exceptions\InvalidCredentialsException $ex){ catch(Exceptions\InvalidCredentialsException){
// "Forbidden" // "Forbidden"
$log->Write('Invalid key: ' . ($_SERVER['HTTP_X_SE_KEY'] ?? '')); $log->Write('Invalid key: ' . ($_SERVER['HTTP_X_SE_KEY'] ?? ''));
http_response_code(403); http_response_code(403);

View file

@ -56,7 +56,7 @@ try{
// "Success, no content" // "Success, no content"
http_response_code(204); http_response_code(204);
} }
catch(Exceptions\InvalidCredentialsException $ex){ catch(Exceptions\InvalidCredentialsException){
// "Forbidden" // "Forbidden"
$log->Write('Couldn\'t validate POST data.'); $log->Write('Couldn\'t validate POST data.');
http_response_code(403); http_response_code(403);