Skip to content

Commit

Permalink
Fix PHPStan Static Analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
chrizzor committed Jul 2, 2024
1 parent 64ce1ff commit e2bdccb
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 57 deletions.
32 changes: 16 additions & 16 deletions Classes/Common/DocumentAnnotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function getAnnotations() {
if ($annotationTarget->isValid()) {

if ($annotationTarget->getId()) {
if ($this->document->getDoc()->getFileLocation($annotationTarget->getId())) {
if ($this->document->getCurrentDocument()->getFileLocation($annotationTarget->getId())) {
if (
$meiTargetPages = $this->getMeasurePagesByFileId(
$annotationTarget->getId(), $annotationTarget->getRangeValue()
Expand Down Expand Up @@ -126,7 +126,7 @@ function getAnnotations() {
}
} elseif ($annotationTarget->getObjectId()) {
$objectTargetPages = [];
foreach ($this->document->getDoc()->physicalStructureInfo as $physInfo) {
foreach ($this->document->getCurrentDocument()->physicalStructureInfo as $physInfo) {
$order = $physInfo['order'];
if ($order) {
$objectTargetPages[] = $order;
Expand Down Expand Up @@ -173,13 +173,13 @@ protected function getPagesByLogicalId($logicalId)
{
$pages = [];
if (
array_key_exists('l2p', $this->document->getDoc()->smLinks) &&
array_key_exists($logicalId, $this->document->getDoc()->smLinks['l2p'])
array_key_exists('l2p', $this->document->getCurrentDocument()->smLinks) &&
array_key_exists($logicalId, $this->document->getCurrentDocument()->smLinks['l2p'])
) {
$physicalIdentifiers = $this->document->getDoc()->smLinks['l2p'][$logicalId];
$physicalIdentifiers = $this->document->getCurrentDocument()->smLinks['l2p'][$logicalId];
foreach ($physicalIdentifiers as $physicalIdentifier) {
if (array_key_exists($physicalIdentifier, $this->document->getDoc()->physicalStructureInfo )) {
$order = $this->document->getDoc()->physicalStructureInfo[$physicalIdentifier]['order'];
if (array_key_exists($physicalIdentifier, $this->document->getCurrentDocument()->physicalStructureInfo )) {
$order = $this->document->getCurrentDocument()->physicalStructureInfo[$physicalIdentifier]['order'];
if (is_numeric($order)) {
$pages[] = $order;
}
Expand All @@ -198,19 +198,19 @@ protected function getPagesByLogicalId($logicalId)
protected function getPagesByPhysicalId($physicalId)
{
$pages = [];
foreach ($this->document->getDoc()->physicalStructureInfo as $id => $physicalInfo) {
foreach ($this->document->getCurrentDocument()->physicalStructureInfo as $id => $physicalInfo) {
$order = $physicalInfo['order'];
if (is_numeric($order)) {
$pages[] = $order;
}
}

if (array_key_exists($physicalId, $this->document->getDoc()->physicalStructureInfo)) {
if ($this->document->getDoc()->physicalStructureInfo[$physicalId]['type'] === 'physSequence') {
if (array_key_exists($physicalId, $this->document->getCurrentDocument()->physicalStructureInfo)) {
if ($this->document->getCurrentDocument()->physicalStructureInfo[$physicalId]['type'] === 'physSequence') {
return $pages;
}

return [$this->document->getDoc()->physicalStructureInfo[$physicalId]['order']];
return [$this->document->getCurrentDocument()->physicalStructureInfo[$physicalId]['order']];
}

return [];
Expand All @@ -226,7 +226,7 @@ protected function getPagesByPhysicalId($physicalId)
protected function getPagesByFileId($fileId)
{
$pages = [];
foreach ($this->document->getDoc()->physicalStructureInfo as $key => $physicalInfo) {
foreach ($this->document->getCurrentDocument()->physicalStructureInfo as $key => $physicalInfo) {
if (
array_key_exists('files', $physicalInfo) &&
is_array($physicalInfo['files']) &&
Expand All @@ -252,7 +252,7 @@ protected function getPagesByFileId($fileId)
*/
protected function getAudioPagesByFileId($fileId, $range = null) {
$tracks = [];
foreach ($this->document->getDoc()->physicalStructureInfo as $key => $physicalInfo) {
foreach ($this->document->getCurrentDocument()->physicalStructureInfo as $key => $physicalInfo) {
if (array_key_exists('tracks', $physicalInfo) && is_array($physicalInfo['tracks'])) {
foreach ($physicalInfo['tracks'] as $track) {
if ($track['fileid'] === $fileId && $track['betype'] === 'TIME') {
Expand Down Expand Up @@ -319,7 +319,7 @@ protected function getMeasurePagesByFileId($fileId, $range = null)
$measureIndex = 1;
$startOrder = 0;
$endOrder = 0;
foreach ($this->document->getDoc()->musicalStructureInfo as $key => $musicalInfo) {
foreach ($this->document->getCurrentDocument()->musicalStructureInfo as $key => $musicalInfo) {

Check failure on line 322 in Classes/Common/DocumentAnnotation.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis

Access to an undefined property Kitodo\Dlf\Common\AbstractDocument::$musicalStructureInfo.
if ($musicalInfo['type'] === 'measure' && is_array($musicalInfo['files'])) {
foreach ($musicalInfo['files'] as $file) {
if ($file['fileid'] === $fileId && $file['type'] === 'IDREF') {
Expand Down Expand Up @@ -365,7 +365,7 @@ protected function getMeasurePagesByFileId($fileId, $range = null)
// Get the related page numbers
$measurePages = [];
foreach ($measures as $measure) {
$measurePages[$measure['order']] = $this->document->getDoc()->musicalStructure[$measure['order']]['page'];
$measurePages[$measure['order']] = $this->document->getCurrentDocument()->musicalStructure[$measure['order']]['page'];

Check failure on line 368 in Classes/Common/DocumentAnnotation.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis

Access to an undefined property Kitodo\Dlf\Common\AbstractDocument::$musicalStructure.
}

return $measurePages;
Expand Down Expand Up @@ -403,7 +403,7 @@ protected static function loadData($document)
$apiBaseUrl = $conf['annotationServerUrl'];

if ($apiBaseUrl) {
$purl = $document->getDoc()->mets->xpath('//mods:mods/mods:identifier[@type="purl"]');
$purl = $document->getCurrentDocument()->mets->xpath('//mods:mods/mods:identifier[@type="purl"]');

Check failure on line 406 in Classes/Common/DocumentAnnotation.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis

Access to an undefined property Kitodo\Dlf\Common\AbstractDocument::$mets.
if (sizeof($purl) > 0) {
$annotationRequest = new AnnotationRequest($apiBaseUrl);
$annotationData = $annotationRequest->getAll((string)$purl[0]);
Expand Down
8 changes: 5 additions & 3 deletions Classes/Common/MetsDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -1537,8 +1537,10 @@ public function __wakeup(): void
*
* @return array Array of musical elements' id, type, label and file representations ordered
* by "@ORDER" attribute
*
* @return array
*/
protected function _getMusicalStructure()
protected function _getMusicalStructure(): array
{
// Is there no musical structure array yet?
if (!$this->musicalStructureLoaded) {
Expand All @@ -1547,7 +1549,7 @@ protected function _getMusicalStructure()
$elementNodes = $this->mets->xpath('./mets:structMap[@TYPE="MUSICAL"]/mets:div[@TYPE="measures"]/mets:div');
if (!empty($elementNodes)) {
// Get file groups.
$fileUse = $this->_getFileGrps();
$fileUse = $this->magicGetFileGrps();

// Get the musical sequence's metadata.
$musicalNode = $this->mets->xpath('./mets:structMap[@TYPE="MUSICAL"]/mets:div[@TYPE="measures"]');
Expand Down Expand Up @@ -1624,7 +1626,7 @@ protected function _getMusicalStructure()
// Get the track/page info (begin and extent time).
$this->musicalStructure = [];
$measurePages = [];
foreach ($this->_getPhysicalStructureInfo() as $physicalId => $page) {
foreach ($this->magicGetPhysicalStructureInfo() as $physicalId => $page) {
if ($page['files']['DEFAULT']) {
$measurePages[$physicalId] = $page['files']['DEFAULT'];
}
Expand Down
6 changes: 3 additions & 3 deletions Classes/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ protected function isDocMissingOrEmpty(): bool
{
return $this->isDocMissing() ||
($this->document->getCurrentDocument()->numPages < 1 &&
$this->document->getDoc()->tableOfContents[0]['type'] != 'multivolume_work'); //@TODO change type
$this->document->getCurrentDocument()->tableOfContents[0]['type'] != 'multivolume_work'); //@TODO change type
}

/**
Expand Down Expand Up @@ -505,14 +505,14 @@ private function getDocumentByUrl(string $documentId)
if ($doc->tableOfContents[0]['type'] === 'multivolume_work') { // @TODO: Change type
$childDocuments = $doc->tableOfContents[0]['children'];
foreach ($childDocuments as $document) {
$this->documentArray[] = Doc::getInstance($document['points'], $this->settings, true);
$this->documentArray[] = AbstractDocument::getInstance($document['points'], $this->settings, true);
}
} else {
$this->documentArray[] = $doc;
}
if ($this->requestData['multipleSource'] && is_array($this->requestData['multipleSource'])) {
foreach ($this->requestData['multipleSource'] as $location) {
$document = Doc::getInstance($location, $this->settings, true);
$document = AbstractDocument::getInstance($location, $this->settings, true);
if ($document !== null) {
$this->documentArray[] = $document;
}
Expand Down
4 changes: 2 additions & 2 deletions Classes/Controller/AnnotationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class AnnotationController extends AbstractController
*/
public function mainAction()
{
$this->loadDocument($this->requestData);
$this->loadDocument();

if (
$this->document === null
|| $this->document->getDoc() === null
|| $this->document->getCurrentDocument() === null
) {
// Quit without doing anything if required variables are not set.
return;
Expand Down
10 changes: 5 additions & 5 deletions Classes/Controller/NavigationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ public function mainAction(): void
}
$this->view->assign('features', $features);

if ($this->document->getDoc()->numMeasures > 0) {
if ($this->document->getCurrentDocument()->numMeasures > 0) {

Check failure on line 119 in Classes/Controller/NavigationController.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis

Access to an undefined property Kitodo\Dlf\Common\AbstractDocument::$numMeasures.
$measureOptions = [];
$measurePages = [];
for ($i = 1; $i <= $this->document->getDoc()->numMeasures; $i++) {
$measureOptions[$i] = '[' . $i . ']' . ($this->document->getDoc()->musicalStructureInfo[$this->document->getDoc()->musicalStructure[$i]['measureid']]['orderlabel'] ? ' - ' . htmlspecialchars($this->document->getDoc()->musicalStructureInfo[$this->document->getDoc()->musicalStructureInfo[$i]]['orderlabel']) : '');
$measurePages[$i] = $this->document->getDoc()->musicalStructure[$i]['page'];
for ($i = 1; $i <= $this->document->getCurrentDocument()->numMeasures; $i++) {
$measureOptions[$i] = '[' . $i . ']' . ($this->document->getCurrentDocument()->musicalStructureInfo[$this->document->getCurrentDocument()->musicalStructure[$i]['measureid']]['orderlabel'] ? ' - ' . htmlspecialchars($this->document->getCurrentDocument()->musicalStructureInfo[$this->document->getCurrentDocument()->musicalStructureInfo[$i]]['orderlabel']) : '');

Check failure on line 123 in Classes/Controller/NavigationController.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis

Access to an undefined property Kitodo\Dlf\Common\AbstractDocument::$musicalStructure.
$measurePages[$i] = $this->document->getCurrentDocument()->musicalStructure[$i]['page'];
}

if (!isset($this->requestData['measure'])) {
Expand All @@ -131,7 +131,7 @@ public function mainAction(): void
}

$this->view->assign('currentMeasure', $currentMeasure);
$this->view->assign('numMeasures', $this->document->getDoc()->numMeasures);
$this->view->assign('numMeasures', $this->document->getCurrentDocument()->numMeasures);
$this->view->assign('measureOptions', $measureOptions);
$this->view->assign('measurePages', $measurePages);
}
Expand Down
56 changes: 31 additions & 25 deletions Classes/Controller/PageViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class PageViewController extends AbstractController
protected array $images = [];

/**
<<<<<<< HEAD
* Holds the current scores' URL, MIME types and the
* id of the current page
*
Expand All @@ -51,14 +50,16 @@ class PageViewController extends AbstractController
*/
protected $scores = [];

/**
* @var array
* @access protected
*/
protected $measures = [];

/**
* Holds the current fulltexts' URLs
*
* @var array
=======
>>>>>>> master
* @access protected
* @var array Holds the current full texts' URLs
*/
Expand Down Expand Up @@ -95,7 +96,7 @@ public function mainAction(): void
// Quit without doing anything if required variables are not set.
return;
} else {
if ($this->document->getDoc()->tableOfContents[0]['type'] == 'multivolume_work' && empty($this->requestData['multiview'])) { // @TODO: Change type
if ($this->document->getCurrentDocument()->tableOfContents[0]['type'] == 'multivolume_work' && empty($this->requestData['multiview'])) { // @TODO: Change type
$params = array_merge(
['tx_dlf' => $this->requestData],
['tx_dlf[multiview]' => 1]
Expand Down Expand Up @@ -139,7 +140,7 @@ public function mainAction(): void
$this->view->assign('docCount', count($this->documentArray));
$this->view->assign('docArray', $this->documentArray);
$this->view->assign('docPage', $this->requestData['docPage']);
$this->view->assign('docType', $this->document->getDoc()->tableOfContents[0]['type']);
$this->view->assign('docType', $this->document->getCurrentDocument()->tableOfContents[0]['type']);

$this->view->assign('multiview', $this->requestData['multiview']);
if ($this->requestData['multiview']) {
Expand Down Expand Up @@ -278,13 +279,15 @@ public function addDocumentAction(FormAddDocument $formAddDocument)
/**
* Get all measures from musical struct
* @param int $page
* @return void
* @param null $specificDoc
* @return array
*/
protected function getMeasures(int $page, $specificDoc = null) {
protected function getMeasures(int $page, $specificDoc = null): array
{
if ($specificDoc) {
$doc = $specificDoc;
} else {
$doc = $this->document->getDoc();
$doc = $this->document->getCurrentDocument();
}
$currentPhysId = $doc->physicalStructure[$page];
$measureCoordsFromCurrentSite = [];
Expand Down Expand Up @@ -315,10 +318,11 @@ protected function getMeasures(int $page, $specificDoc = null) {
protected function getScore(int $page, $specificDoc = null)
{
$score = [];
$loc = '';
if ($specificDoc) {
$doc = $specificDoc;
} else {
$doc = $this->document->getDoc();
$doc = $this->document->getCurrentDocument();
}
$fileGrpsScores = GeneralUtility::trimExplode(',', $this->extConf['fileGrpScore']);

Expand All @@ -332,22 +336,24 @@ protected function getScore(int $page, $specificDoc = null)
}
}

$score['mimetype'] = $doc->getFileMimeType($loc);
$score['pagebeginning'] = $doc->getPageBeginning($pageId, $loc);
$score['url'] = $doc->getFileLocation($loc);
if ($this->settings['useInternalProxy']) {
// Configure @action URL for form.
$uri = $this->uriBuilder->reset()
->setTargetPageUid($GLOBALS['TSFE']->id)
->setCreateAbsoluteUri(!empty($this->settings['forceAbsoluteUrl']) ? true : false)
->setArguments([
'eID' => 'tx_dlf_pageview_proxy',
'url' => $score['url'],
'uHash' => GeneralUtility::hmac($score['url'], 'PageViewProxy')
])
->build();

$score['url'] = $uri;
if (!empty($loc)) {
$score['mimetype'] = $doc->getFileMimeType($loc);
$score['pagebeginning'] = $doc->getPageBeginning($pageId, $loc);
$score['url'] = $doc->getFileLocation($loc);
if ($this->settings['useInternalProxy']) {
// Configure @action URL for form.
$uri = $this->uriBuilder->reset()
->setTargetPageUid($GLOBALS['TSFE']->id)
->setCreateAbsoluteUri(!empty($this->settings['forceAbsoluteUrl']) ? true : false)
->setArguments([

Check notice on line 348 in Classes/Controller/PageViewController.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Classes/Controller/PageViewController.php#L348

Opening parenthesis of a multi-line function call must be the last content on the line
'eID' => 'tx_dlf_pageview_proxy',
'url' => $score['url'],
'uHash' => GeneralUtility::hmac($score['url'], 'PageViewProxy')
])
->build();

$score['url'] = $uri;
}
}

if (empty($score)) {
Expand Down
4 changes: 2 additions & 2 deletions Classes/Controller/ToolboxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ public function scoretool()
{
if (
$this->document === null
|| $this->document->getDoc()->numPages < 1
|| $this->document->getCurrentDocument()->numPages < 1
|| empty($this->extConf['fileGrpScore'])
) {
// Quit without doing anything if required variables are not set.
return;
}
$fileGrpsScores = GeneralUtility::trimExplode(',', $this->extConf['fileGrpScore']);
foreach ($fileGrpsScores as $fileGrpScore) {
foreach ($this->document->getDoc()->physicalStructureInfo as $page) {
foreach ($this->document->getCurrentDocument()->physicalStructureInfo as $page) {
if (isset($page['files'])) {
$files = $page['files'];
} else {
Expand Down
2 changes: 1 addition & 1 deletion Classes/ViewHelpers/ImplodeViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function initializeArguments()
/**
* Checks if a value exists in an array.
*
* @return bool
* @return string
*/
public function render()
{
Expand Down

0 comments on commit e2bdccb

Please sign in to comment.