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 May 28, 2024
1 parent 5ab2cfd commit d053008
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 33 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
3 changes: 0 additions & 3 deletions Classes/Common/AbstractDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -1369,9 +1369,6 @@ public function getPageLink($pageNumber)

public function toArray($uriBuilder, array $config = [])
{
$proxyFileGroups = $config['proxyFileGroups'] ?? [];
$forceAbsoluteUrl = $config['forceAbsoluteUrl'] ?? false;

$this->magicGetSmLinks();
$this->magicGetPhysicalStructure();

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 @@ -375,6 +375,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);
}
}
}

/**
* Parse title of parent document if needed.
*
Expand Down Expand Up @@ -474,15 +493,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 d053008

Please sign in to comment.