From 40028a462bc2480304dee8226bdaf65388465841 Mon Sep 17 00:00:00 2001 From: Christopher Timm Date: Wed, 3 Jul 2024 16:25:03 +0200 Subject: [PATCH] Codacy fix --- Classes/Common/DocumentAnnotation.php | 10 +++++----- Classes/Common/MetsDocument.php | 6 +++--- Classes/Controller/PageViewController.php | 6 +++--- Classes/Domain/Model/AnnotationTarget.php | 16 ++++++++-------- .../Public/JavaScript/PageView/ScoreControl.js | 4 ++-- .../Public/JavaScript/PageView/gridstack.js | 1 + 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/Classes/Common/DocumentAnnotation.php b/Classes/Common/DocumentAnnotation.php index 90c0a85b8..12ad18fd2 100644 --- a/Classes/Common/DocumentAnnotation.php +++ b/Classes/Common/DocumentAnnotation.php @@ -200,7 +200,7 @@ protected function getPagesByLogicalId($logicalId) protected function getPagesByPhysicalId($physicalId) { $pages = []; - foreach ($this->document->getCurrentDocument()->physicalStructureInfo as $id => $physicalInfo) { + foreach ($this->document->getCurrentDocument()->physicalStructureInfo as $physicalInfo) { $order = $physicalInfo['order']; if (is_numeric($order)) { $pages[] = $order; @@ -228,7 +228,7 @@ protected function getPagesByPhysicalId($physicalId) protected function getPagesByFileId($fileId) { $pages = []; - foreach ($this->document->getCurrentDocument()->physicalStructureInfo as $key => $physicalInfo) { + foreach ($this->document->getCurrentDocument()->physicalStructureInfo as $physicalInfo) { if ( array_key_exists('files', $physicalInfo) && is_array($physicalInfo['files']) && @@ -287,7 +287,7 @@ protected function getAudioPagesByFileId($fileId, $range = null) { if ( !( $intervalFrom < $end && ( - is_null($intervalTo) || $intervalTo > $begin + $intervalTo === null || $intervalTo > $begin ) ) ) { @@ -299,7 +299,7 @@ protected function getAudioPagesByFileId($fileId, $range = null) { // Get the related page numbers $trackPages = []; foreach ($tracks as $track) { - if (!is_null($track['order'])) { + if ($track['order'] !== null) { $trackPages[] = $track['order']; } } @@ -406,7 +406,7 @@ protected static function loadData($document) if ($apiBaseUrl) { $purl = $document->getCurrentDocument()->mets->xpath('//mods:mods/mods:identifier[@type="purl"]'); - if (sizeof($purl) > 0) { + if (count($purl) > 0) { $annotationRequest = new AnnotationRequest($apiBaseUrl); $annotationData = $annotationRequest->getAll((string)$purl[0]); } diff --git a/Classes/Common/MetsDocument.php b/Classes/Common/MetsDocument.php index 08ff6f0d6..a33914d59 100644 --- a/Classes/Common/MetsDocument.php +++ b/Classes/Common/MetsDocument.php @@ -1544,6 +1544,7 @@ protected function _getMusicalStructure(): array // Does the document have a structMap node of type "MUSICAL"? $elementNodes = $this->mets->xpath('./mets:structMap[@TYPE="MUSICAL"]/mets:div[@TYPE="measures"]/mets:div'); if (!empty($elementNodes)) { + $musicalSeq = []; // Get file groups. $fileUse = $this->magicGetFileGrps(); @@ -1578,6 +1579,8 @@ protected function _getMusicalStructure(): array } } + $elements = []; + // Build the physical elements' array from the physical structMap node. foreach ($elementNodes as $elementNode) { $elements[(int) $elementNode['ORDER']] = (string) $elementNode['ID']; @@ -1615,9 +1618,6 @@ protected function _getMusicalStructure(): array // Set total number of measures. $this->numMeasures = count($elements); - // Merge and re-index the array to get nice numeric indexes. - $measures = array_merge($musicalSeq, $elements); - // Get the track/page info (begin and extent time). $this->musicalStructure = []; $measurePages = []; diff --git a/Classes/Controller/PageViewController.php b/Classes/Controller/PageViewController.php index 033d9b5ff..4ffcdcb13 100644 --- a/Classes/Controller/PageViewController.php +++ b/Classes/Controller/PageViewController.php @@ -297,7 +297,7 @@ protected function getMeasures(int $page, $specificDoc = null): array $musicalStruct = $doc->musicalStructureInfo; $i = 0; - foreach ($musicalStruct as $measureId => $measureData) { + foreach ($musicalStruct as $measureData) { if ($defaultFileId == $measureData['files']['DEFAULT']['fileid']) { $measureCoordsFromCurrentSite[$measureData['files']['SCORE']['begin']] = $measureData['files']['DEFAULT']['coords']; $measureCounterToMeasureId[$i] = $measureData['files']['SCORE']['begin']; @@ -345,7 +345,7 @@ protected function getScore(int $page, $specificDoc = null) if ($this->settings['useInternalProxy']) { // Configure @action URL for form. $uri = $this->uriBuilder->reset() - ->setTargetPageUid($GLOBALS['TSFE']->id) + ->setTargetPageUid($this->pageUid) ->setCreateAbsoluteUri(!empty($this->settings['forceAbsoluteUrl']) ? true : false) ->setArguments([ 'eID' => 'tx_dlf_pageview_proxy', @@ -412,10 +412,10 @@ protected function addViewerJS(): void $this->document->getCurrentDocument()->tableOfContents[0]['type'] == 'multivolume_work') { // @todo Change type $jsViewer = 'tx_dlf_viewer = [];'; $i = 0; - $globalPage = $this->requestData['page']; foreach ($this->documentArray as $document) { if ($document !== null) { $docPage = $this->requestData['docPage'][$i]; + $docImage = []; // check if page or measure is set if ($this->requestData['docMeasure'][$i]) { diff --git a/Classes/Domain/Model/AnnotationTarget.php b/Classes/Domain/Model/AnnotationTarget.php index a9a77e7ac..bf1ccd0d1 100644 --- a/Classes/Domain/Model/AnnotationTarget.php +++ b/Classes/Domain/Model/AnnotationTarget.php @@ -118,15 +118,15 @@ public function isValidRange() if (empty($this->rangeParameterName) && empty($this->rangeValue)) { return true; } elseif ($this->isFacsimileRange()) { - return 1 === preg_match("/^(\d+)(,\d+){3}?$/", $this->rangeValue); + return preg_match("/^(\d+)(,\d+){3}?$/", $this->rangeValue) === 1; } elseif($this->isAudioRange()) { - return 1 === preg_match( + return preg_match( "/^(?:\d+(?:\.\d*)?|\.\d+){0,1}(?:,(?:\d+(?:\.\d*)?|\.\d+))*$/", $this->rangeValue - ); + ) === 1; } elseif($this->isScoreRange()) { - return 1 === preg_match("/^((\d+|start|end|all|(\d+|start)(-(\d+|end)){0,1})+)(,(\d+|start|end|all|(\d+|start)(-(\d+|end)){0,1})+){0,}?$/", - $this->rangeValue); + return preg_match("/^((\d+|start|end|all|(\d+|start)(-(\d+|end)){0,1})+)(,(\d+|start|end|all|(\d+|start)(-(\d+|end)){0,1})+){0,}?$/", + $this->rangeValue) === 1; } return false; @@ -137,7 +137,7 @@ public function isValidRange() */ public function isScoreRange() { - return 'measureRanges' === $this->getRangeParameterName(); + return $this->getRangeParameterName() === 'measureRanges' ; } /** @@ -145,7 +145,7 @@ public function isScoreRange() */ public function isAudioRange() { - return 't' === $this->getRangeParameterName(); + return $this->getRangeParameterName() === 't'; } /** @@ -153,7 +153,7 @@ public function isAudioRange() */ public function isFacsimileRange() { - return 'xywh' === $this->getRangeParameterName(); + return $this->getRangeParameterName() === 'xywh'; } } diff --git a/Resources/Public/JavaScript/PageView/ScoreControl.js b/Resources/Public/JavaScript/PageView/ScoreControl.js index 53dc7c5c1..1e152c601 100644 --- a/Resources/Public/JavaScript/PageView/ScoreControl.js +++ b/Resources/Public/JavaScript/PageView/ScoreControl.js @@ -7,7 +7,7 @@ * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. */ - +/*global ol */ const className = 'score-visible'; const scrollOffset = 100; var zoom = 40; @@ -96,7 +96,7 @@ dlfScoreUtil.fetchScoreDataFromServer = function (url, pagebeginning) { /** * Encapsulates especially the score behavior - * @constructor + * @class * @param {ol.Map} map */ const dlfViewerScoreControl = function (dlfViewer, pagebeginning, pagecount) { diff --git a/Resources/Public/JavaScript/PageView/gridstack.js b/Resources/Public/JavaScript/PageView/gridstack.js index 9d68dbe2f..dadef1ed8 100644 --- a/Resources/Public/JavaScript/PageView/gridstack.js +++ b/Resources/Public/JavaScript/PageView/gridstack.js @@ -1,3 +1,4 @@ +/*global GridStack */ $( document ).ready(function() { var options = { // put in gridstack options here disableOneColumnMode: true, // for jfiddle small window size