Skip to content

Commit

Permalink
Fix errors marked by PHPStan
Browse files Browse the repository at this point in the history
  • Loading branch information
beatrycze-volk committed Oct 25, 2023
1 parent 8636cae commit b12ca3e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .github/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ parameters:
- '#Call to an undefined method Kitodo\\Dlf\\Domain\\Repository\\[a-zA-Z]+Repository::findOneByUid\(\)\.#'
- '#Call to an undefined method Psr\\Http\\Message\\RequestFactoryInterface::request\(\)\.#'
- '#Call to an undefined method Solarium\\Core\\Query\\DocumentInterface::setField\(\)\.#'
- '#Call to an undefined method Ubl\\Iiif\\Presentation\\Common\\Model\\Resources\\CanvasInterface::getImages\(\)\.#'
- '#Call to an undefined method Ubl\\Iiif\\Presentation\\Common\\Model\\Resources\\CanvasInterface::getOtherContent\(\)\.#'
- '#Call to an undefined method Ubl\\Iiif\\Presentation\\Common\\Model\\Resources\\IiifResourceInterface::getHeight\(\)\.#'
- '#Call to an undefined method Ubl\\Iiif\\Presentation\\Common\\Model\\Resources\\IiifResourceInterface::getWidth\(\)\.#'
- '#Call to an undefined method Ubl\\Iiif\\Presentation\\Common\\Model\\Resources\\IiifResourceInterface::getPossibleTextAnnotationContainers\(\)\.#'
Expand Down
25 changes: 5 additions & 20 deletions Classes/Controller/DocumentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,18 @@ class DocumentController extends AbstractController
*
* @access public
*
* @param string $content: The PlugIn content
* @param array $conf: The PlugIn configuration
*
* @return string The content that is displayed on the website
* @return void
*/
public function mainAction()
{
// Load current document.
$this->loadDocument($this->requestData);
$this->loadDocument();
if ($this->isDocMissingOrEmpty()) {
// Quit without doing anything if required variables are not set.
return;
} else {
if (!empty($this->requestData['logicalPage'])) {
$this->requestData['page'] = $this->document->getDoc()->getPhysicalPage($this->requestData['logicalPage']);
// The logical page parameter should not appear again
unset($this->requestData['logicalPage']);
}
// Set default values if not set.
// $this->requestData['page'] may be integer or string (physical structure @ID)
if ((int) $this->requestData['page'] > 0 || empty($this->requestData['page'])) {
$this->requestData['page'] = MathUtility::forceIntegerInRange((int) $this->requestData['page'], 1, $this->document->getDoc()->numPages, 1);
} else {
$this->requestData['page'] = array_search($this->requestData['page'], $this->document->getDoc()->physicalStructure);
}
$this->requestData['double'] = MathUtility::forceIntegerInRange($this->requestData['double'], 0, 1, 0);
}

$this->setPage();

$metadataUrl = null;

Expand Down Expand Up @@ -93,7 +78,7 @@ public function mainAction()
'fulltext' => $fulltextFileGroups,
'download' => GeneralUtility::trimExplode(',', $this->extConf['fileGrpDownload']),
],
'document' => $this->document->getDoc()->toArray($this->uriBuilder, $config),
'document' => $this->document->getCurrentDocument()->toArray($this->uriBuilder, $config),
];

$docConfiguration = '
Expand Down
30 changes: 21 additions & 9 deletions Classes/Controller/MetadataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,25 @@ private function parseMetadata(int $i, string $name, $value, array &$metadata) :
}
}

/**
* Get metadata for given id array.
*
* @access private
*
* @param array $toc table of content
* @param array &$output metadata
*
* @return void
*/
private function getIds($toc, &$output) {
foreach ($toc as $entry) {
$output[$entry['id']] = true;
if (is_array($entry['children'])) {
$this->getIds($entry['children'], $output);
}
}
}

/**
* Get metadata for given id array.
*
Expand All @@ -403,15 +422,8 @@ private function getMetadata(): array
// Collect IDs of all logical structures. This is a flattened tree, so the
// order also works for rootline configurations.
$allIds = [];
function getIds($toc, &$output) {
foreach ($toc as $entry) {
$output[$entry['id']] = true;
if (is_array($entry['children'])) {
getIds($entry['children'], $output);
}
}
}
getIds($this->currentDocument->tableOfContents, $allIds);

$this->getIds($this->currentDocument->tableOfContents, $allIds);

$idIsActive = [];
foreach ($ids as $id) {
Expand Down
2 changes: 1 addition & 1 deletion Classes/Controller/PageViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ protected function addViewerJS(): void
'maxPage' => $this->requestData['page'] + $this->requestData['double']
];

$initDoc = $this->document->getDoc()->toArray($this->uriBuilder, $config);
$initDoc = $this->document->getCurrentDocument()->toArray($this->uriBuilder, $config);

// Viewer configuration.
$viewerConfiguration = '
Expand Down

0 comments on commit b12ca3e

Please sign in to comment.