Skip to content

Commit

Permalink
Fix function nesting level
Browse files Browse the repository at this point in the history
  • Loading branch information
chrizzor committed Jun 28, 2024
1 parent c8200eb commit 2311c83
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions Classes/Common/MetsDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,27 +545,9 @@ private function getSubentries($allSubentries, string $parentIndex, \DOMNode $pa
$theseSubentries = [];
foreach ($allSubentries as $subentry) {
if ($subentry['parent_index_name'] == $parentIndex) {
if (
!empty($subentry['xpath'])
&& ($values = $domXPath->evaluate($subentry['xpath'], $parentNode))
) {
if (
($values instanceof \DOMNodeList
&& $values->length > 0) || is_string($values)
) {
if (is_string($values)) {
// if concat is used evaluate returns a string
$theseSubentries[$subentry['index_name']][] = trim($values);
} else {
foreach ($values as $value) {
if (!empty(trim((string) $value->nodeValue))) {
$theseSubentries[$subentry['index_name']][] = trim((string) $value->nodeValue);
}
}
}
} elseif (!($values instanceof \DOMNodeList)) {
$theseSubentries[$subentry['index_name']] = [trim((string) $values->nodeValue)];
}
$values = $domXPath->evaluate($subentry['xpath'], $parentNode);
if (!empty($subentry['xpath']) && ($values)) {
array_merge($theseSubentries, $this->getSubentryValue($values, $subentry));

Check failure on line 550 in Classes/Common/MetsDocument.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis

Call to function array_merge() on a separate line has no effect.
}
// Set default value if applicable.
if (
Expand All @@ -582,6 +564,34 @@ private function getSubentries($allSubentries, string $parentIndex, \DOMNode $pa
return $theseSubentries;
}

/**
* @param $values
* @param $subentry
* @return array
*/
private function getSubentryValue($values, $subentry)
{
$theseSubentries = [];
if (
($values instanceof \DOMNodeList
&& $values->length > 0) || is_string($values)
) {
if (is_string($values)) {
// if concat is used evaluate returns a string
$theseSubentries[$subentry['index_name']][] = trim($values);
} else {
foreach ($values as $value) {
if (!empty(trim((string) $value->nodeValue))) {
$theseSubentries[$subentry['index_name']][] = trim((string) $value->nodeValue);
}
}
}
} elseif (!($values instanceof \DOMNodeList)) {
$theseSubentries[$subentry['index_name']] = [trim((string) $values->nodeValue)];
}
return $theseSubentries;
}

/**
* Get logical unit type.
*
Expand Down

0 comments on commit 2311c83

Please sign in to comment.