Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
GaziYucel committed Mar 1, 2024
1 parent 8d212fb commit 281d4c8
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions classes/External/OpenAlex/Enrich.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function execute(): bool
if ($citation->isProcessed || empty($citation->doi) || !empty($citation->openalex_id))
continue;

$citation = $this->getWork($citation);
$citation = $this->getCitationWork($citation);

if (!empty($citation->openalex_id)) $citation->isProcessed = true;
$citation->openalex_id = OpenAlex::removePrefix($citation->openalex_id);
Expand All @@ -77,13 +77,30 @@ public function execute(): bool
return true;
}

/**
* Get openalex id for journal
*
* @param string|null $issn
* @param MetadataJournal $metadataJournal
* @return MetadataJournal
*/
public function getJournal(?string $issn, MetadataJournal $metadataJournal): MetadataJournal
{
$source = $this->api->getSource($issn);

if (!empty($source) && !empty($source['id']) && !empty($source['issn_l'] && $source['issn_l'] === $issn))
$metadataJournal->openalex_id = OpenAlex::removePrefix($source['id']);

return $metadataJournal;
}

/**
* Get citation (work) from external service
*
* @param CitationModel $citation
* @return CitationModel
*/
public function getWork(CitationModel $citation): CitationModel
public function getCitationWork(CitationModel $citation): CitationModel
{
$openAlexArray = $this->api->getWork(Doi::removePrefix($citation->doi));

Expand All @@ -93,7 +110,7 @@ public function getWork(CitationModel $citation): CitationModel
switch ($key) {
case 'authors':
foreach ($openAlexArray['authorships'] as $index => $authorship) {
$citation->authors[] = $this->getAuthor($authorship);
$citation->authors[] = $this->getCitationAuthor($authorship);
}
break;
default:
Expand All @@ -110,30 +127,13 @@ public function getWork(CitationModel $citation): CitationModel
return $citation;
}

/**
* Get openalex id for journal
*
* @param string|null $issn
* @param MetadataJournal $metadataJournal
* @return MetadataJournal
*/
public function getJournal(?string $issn, MetadataJournal $metadataJournal): MetadataJournal
{
$source = $this->api->getSource($issn);

if (!empty($source) && !empty($source['id']) && !empty($source['issn_l'] && $source['issn_l'] === $issn))
$metadataJournal->openalex_id = OpenAlex::removePrefix($source['id']);

return $metadataJournal;
}

/**
* Convert to AuthorModel with mappings
*
* @param array $authorIn Input values
* @return AuthorModel
*/
private function getAuthor(array $authorIn): AuthorModel
private function getCitationAuthor(array $authorIn): AuthorModel
{
$authorOut = new AuthorModel();
$mappings = Mappings::getAuthor();
Expand Down

0 comments on commit 281d4c8

Please sign in to comment.