Skip to content

Commit

Permalink
Further decrease of complexity in getLogicalStructureInfo() function
Browse files Browse the repository at this point in the history
Codacy still point too high complexity in this function
  • Loading branch information
beatrycze-volk committed Jul 2, 2024
1 parent 5837a04 commit 698f42d
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions Classes/Common/MetsDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,18 +344,10 @@ protected function getLogicalStructureInfo(SimpleXMLElement $structure, bool $re
$this->magicGetSmLinks();
// Load physical structure.
$this->magicGetPhysicalStructure();
// Get the physical page or external file this structure element is pointing at.

$this->getPage($details, $structure->children('http://www.loc.gov/METS/')->mptr);
$this->getFiles($details, $structure->children('http://www.loc.gov/METS/')->fptr);

// Get the files this structure element is pointing at.
$fileUse = $this->magicGetFileGrps();
// Get the file representations from fileSec node.
foreach ($structure->children('http://www.loc.gov/METS/')->fptr as $fptr) {
// Check if file has valid @USE attribute.
if (!empty($fileUse[(string) $fptr->attributes()->FILEID])) {
$details['files'][$fileUse[(string) $fptr->attributes()->FILEID]] = (string) $fptr->attributes()->FILEID;
}
}
// Keep for later usage.
$this->logicalUnits[$details['id']] = $details;
// Walk the structure recursively? And are there any children of the current element?
Expand All @@ -372,6 +364,26 @@ protected function getLogicalStructureInfo(SimpleXMLElement $structure, bool $re
return $details;
}

/**
* Get the files this structure element is pointing at.
*
* @param ?SimpleXMLElement $filePointers
*
* @return void
*/
private function getFiles(array &$details, ?SimpleXMLElement $filePointers): void
{
$fileUse = $this->magicGetFileGrps();
// Get the file representations from fileSec node.
foreach ($filePointers as $filePointer) {
$fileId = (string) $filePointer->attributes()->FILEID;
// Check if file has valid @USE attribute.
if (!empty($fileUse[$fileId])) {
$details['files'][$fileUse[$fileId]] = $fileId;
}
}
}

/**
* Get the physical page or external file this structure element is pointing at.
*
Expand All @@ -382,7 +394,8 @@ protected function getLogicalStructureInfo(SimpleXMLElement $structure, bool $re
*
* @return void
*/
private function getPage(array &$details, ?SimpleXMLElement $metsPointers) {
private function getPage(array &$details, ?SimpleXMLElement $metsPointers): void
{
if (count($metsPointers)) {
// Yes. Get the file reference.
$details['points'] = (string) $metsPointers[0]->attributes('http://www.w3.org/1999/xlink')->href;
Expand Down

0 comments on commit 698f42d

Please sign in to comment.