Skip to content

Commit

Permalink
fix: do not proceed if no setting found
Browse files Browse the repository at this point in the history
Removes an unecessary fetch() call as find(true)
already executes a fetch(), and changes the
control flow so that getLibKeyLink() returns
null early if no setting is found (only move on
to creating an instance of CurlWrapper if the
setting was found).
  • Loading branch information
Chloe070196 committed Dec 3, 2024
1 parent 64e4a9c commit df58ae1
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions code/web/Drivers/LibKeyDriver.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php

class LibKeyDriver {

public function getLibKeyLink(string $doiUrl): string | null {
require_once ROOT_DIR . '/sys/LibKey/LibKeySetting.php';
$activeLibrary = Library::getActiveLibrary();
$settings = new LibKeySetting();
$settings->whereAdd("id=$activeLibrary->libKeySettingId");
if ($settings->find(true)) {
$settings->fetch();
if (!$settings->find(true)) {
return null;
}
$curlWrapper = new CurlWrapper;
$response = $curlWrapper->curlGetPage("https://public-api.thirdiron.com/public/v1/libraries/" . $settings->libraryId . "/articles/doi/" . $this->extractDoi($doiUrl) . "?access_token=" . $settings->apiKey);
Expand Down

0 comments on commit df58ae1

Please sign in to comment.