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;
}
}
catch(Exception $ex){
catch(Exception){
// Invalid XML
return true;
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -61,7 +61,7 @@ class PollVote extends PropertiesBase{
$vote = PollVote::Get($this->PollItem->Poll->UrlName, $this->UserId);
$error->Add(new Exceptions\PollVoteExistsException($vote));
}
catch(Exceptions\InvalidPollVoteException $ex){
catch(Exceptions\InvalidPollVoteException){
// User hasn't voted yet, carry on
}
@ -81,7 +81,7 @@ class PollVote extends PropertiesBase{
$this->User = User::GetByEmail($email);
$this->UserId = $this->User->UserId;
}
catch(Exceptions\InvalidUserException $ex){
catch(Exceptions\InvalidUserException){
// Can't validate patron email - do nothing for now,
// 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,

View file

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

View file

@ -105,7 +105,7 @@ try{
try{
$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.');
continue;
}
@ -147,7 +147,7 @@ try{
$payment->User = null;
}
}
catch(Exception $ex){
catch(Exception){
// Anonymous donations don't have these elements present and will throw an exception
$payment->User = null;
}
@ -172,7 +172,7 @@ try{
try{
$payment->Create();
}
catch(Exceptions\PaymentExistsException $ex){
catch(Exceptions\PaymentExistsException){
// Payment already exists, just continue
$log->Write('Donation already in database.');
continue;
@ -217,7 +217,7 @@ try{
try{
$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 ...');

View file

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

View file

@ -32,7 +32,7 @@ try{
header('Content-Disposition: attachment; filename="' . basename($path) . '"');
exit();
}
catch(Exceptions\LoginRequiredException $ex){
catch(Exceptions\LoginRequiredException){
if(isset($_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);
}
catch(Exceptions\InvalidFileException $ex){
catch(Exceptions\InvalidFileException){
Template::Emit404();
}

View file

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

View file

@ -23,7 +23,7 @@ try{
$author = strip_tags($ebooks[0]->AuthorsHtml);
$authorUrl = Formatter::ToPlainText($ebooks[0]->AuthorsUrl);
}
catch(Exceptions\InvalidAuthorException $ex){
catch(Exceptions\InvalidAuthorException){
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]) ?>

View file

@ -43,7 +43,7 @@ try{
try{
$ebook = apcu_fetch('ebook-' . $wwwFilesystemPath);
}
catch(Safe\Exceptions\ApcuException $ex){
catch(Safe\Exceptions\ApcuException){
$ebook = new Ebook($wwwFilesystemPath);
}
@ -106,7 +106,7 @@ catch(Exceptions\SeeOtherEbookException $ex){
header('Location: ' . $ex->Url);
exit();
}
catch(Exceptions\InvalidEbookException $ex){
catch(Exceptions\InvalidEbookException){
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]) ?>

View file

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

View file

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

View file

@ -29,7 +29,7 @@ if($type === 'atom'){
try{
$feeds = apcu_fetch('feeds-index-' . $type . '-' . $class);
}
catch(Safe\Exceptions\ApcuException $ex){
catch(Safe\Exceptions\ApcuException){
$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 . '.']) ?>

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -133,7 +133,7 @@ try{
// "Success, no content"
http_response_code(204);
}
catch(Exceptions\InvalidCredentialsException $ex){
catch(Exceptions\InvalidCredentialsException){
// "Forbidden"
http_response_code(403);
}
@ -149,7 +149,7 @@ catch(Exceptions\WebhookException $ex){
// "Client error"
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.
// 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"
http_response_code(204);
}
catch(Exceptions\InvalidCredentialsException $ex){
catch(Exceptions\InvalidCredentialsException){
// "Forbidden"
$log->Write('Invalid key: ' . ($_SERVER['HTTP_X_SE_KEY'] ?? ''));
http_response_code(403);

View file

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