Skip to content

Commit

Permalink
Make Scrutinizer happy
Browse files Browse the repository at this point in the history
  • Loading branch information
XavRsl committed Jun 20, 2018
1 parent 287c0cb commit c3bafba
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 17 deletions.
72 changes: 57 additions & 15 deletions src/Resources/Extractors/EutilsEfetch.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,7 @@ public function extractJournalData()
public function extractAuthorsData()
{
try {
foreach ($this->searchTree->MedlineCitation->Article->AuthorList->Author as $author) {
if (! empty($lastName = get_string($author, 'LastName'))) {
$affiliations = [];
foreach ($author->AffiliationInfo as $affiliation) {
$affiliations[]['name'] = get_string($affiliation, 'Affiliation');
}

$this->output['authors'][] = [
'first_name' => get_string($author, 'ForeName'),
'last_name' => $lastName,
'email' => get_string(find_emails_in_array(Arr::pluck($affiliations, 'name')), 0),
'affiliation' => $affiliations,
];
}
}
$this->loopOverAuthors();
} catch (\Exception $e) {
// Empty catch block, don't want anything to happen in case of exception.
}
Expand All @@ -105,4 +91,60 @@ protected function getIssns()

return $issn;
}

/**
* Loop over authors array.
*/
protected function loopOverAuthors(): void
{
foreach ($this->searchTree->MedlineCitation->Article->AuthorList->Author as $author) {
$this->createAuthorEntry($author);
}
}

/**
* Create an author entry in output.
*
* @param $author
*/
protected function createAuthorEntry($author): void
{
if (! empty($lastName = get_string($author, 'LastName'))) {
$affiliations = $this->loopOverAffiliations($author);

$this->output['authors'][] = [
'first_name' => get_string($author, 'ForeName'),
'last_name' => $lastName,
'email' => $this->getEmailsFromAffiliations($affiliations),
'affiliation' => $affiliations,
];
}
}

/**
* Loop over affiliations.
*
* @param array $author
* @return array
*/
protected function loopOverAffiliations($author): array
{
$affiliations = [];
foreach ($author->AffiliationInfo as $affiliation) {
$affiliations[]['name'] = get_string($affiliation, 'Affiliation');
}

return $affiliations;
}

/**
* Get emails from affiliations array.
*
* @param array $affiliations
* @return string
*/
protected function getEmailsFromAffiliations($affiliations): string
{
return get_string(find_emails_in_array(Arr::pluck($affiliations, 'name')), 0);
}
}
4 changes: 2 additions & 2 deletions src/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ function date_from_parseable_format($string)
*
* @param array $array
* @param $key
* @param mixed $default
* @return mixed
* @param mixed $default
* @return string
*/
function get_string($array, $key, $default = null)
{
Expand Down

0 comments on commit c3bafba

Please sign in to comment.