From b12ca3e82962abd2114e6944535298fa29e02f42 Mon Sep 17 00:00:00 2001 From: Beatrycze Volk Date: Wed, 25 Oct 2023 11:05:59 +0200 Subject: [PATCH] Fix errors marked by PHPStan --- .github/phpstan.neon | 2 ++ Classes/Controller/DocumentController.php | 25 ++++--------------- Classes/Controller/MetadataController.php | 30 ++++++++++++++++------- Classes/Controller/PageViewController.php | 2 +- 4 files changed, 29 insertions(+), 30 deletions(-) diff --git a/.github/phpstan.neon b/.github/phpstan.neon index fa63a34816..04e6b577ac 100644 --- a/.github/phpstan.neon +++ b/.github/phpstan.neon @@ -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\(\)\.#' diff --git a/Classes/Controller/DocumentController.php b/Classes/Controller/DocumentController.php index 4781fa37ac..8925b10728 100644 --- a/Classes/Controller/DocumentController.php +++ b/Classes/Controller/DocumentController.php @@ -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; @@ -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 = ' diff --git a/Classes/Controller/MetadataController.php b/Classes/Controller/MetadataController.php index dc1aa16b61..1ad329d3c4 100644 --- a/Classes/Controller/MetadataController.php +++ b/Classes/Controller/MetadataController.php @@ -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. * @@ -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) { diff --git a/Classes/Controller/PageViewController.php b/Classes/Controller/PageViewController.php index bbefe615da..8ca6d56dbe 100644 --- a/Classes/Controller/PageViewController.php +++ b/Classes/Controller/PageViewController.php @@ -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 = '