Passed
Pull Request — master (#13)
by
unknown
05:42
created
Classes/Common/MetsDocument.php 1 patch
Braces   +29 added lines, -58 removed lines patch added patch discarded remove patch
@@ -47,8 +47,7 @@  discard block
 block discarded – undo
47 47
  * @property-read string $toplevelId This holds the toplevel structure's @ID (METS) or the manifest's @id (IIIF)
48 48
  * @property-read mixed $uid This holds the UID or the URL of the document
49 49
  */
50
-final class MetsDocument extends Document
51
-{
50
+final class MetsDocument extends Document {
52 51
     /**
53 52
      * This holds the whole XML file as string for serialization purposes
54 53
      * @see __sleep() / __wakeup()
@@ -127,8 +126,7 @@  discard block
 block discarded – undo
127 126
      *
128 127
      * @return  void
129 128
      */
130
-    public function addMetadataFromMets(&$metadata, $id)
131
-    {
129
+    public function addMetadataFromMets(&$metadata, $id) {
132 130
         $details = $this->getLogicalStructure($id);
133 131
         if (!empty($details)) {
134 132
             $metadata['mets_label'][0] = $details['label'];
@@ -141,8 +139,7 @@  discard block
 block discarded – undo
141 139
      * {@inheritDoc}
142 140
      * @see \Kitodo\Dlf\Common\Document::establishRecordId()
143 141
      */
144
-    protected function establishRecordId($pid)
145
-    {
142
+    protected function establishRecordId($pid) {
146 143
         // Check for METS object @ID.
147 144
         if (!empty($this->mets['OBJID'])) {
148 145
             $this->recordId = (string) $this->mets['OBJID'];
@@ -162,8 +159,7 @@  discard block
 block discarded – undo
162 159
      * {@inheritDoc}
163 160
      * @see \Kitodo\Dlf\Common\Document::getDownloadLocation()
164 161
      */
165
-    public function getDownloadLocation($id)
166
-    {
162
+    public function getDownloadLocation($id) {
167 163
         $fileMimeType = $this->getFileMimeType($id);
168 164
         $fileLocation = $this->getFileLocation($id);
169 165
         if ($fileMimeType == 'application/vnd.kitodo.iiif') {
@@ -188,8 +184,7 @@  discard block
 block discarded – undo
188 184
      * {@inheritDoc}
189 185
      * @see \Kitodo\Dlf\Common\Document::getFileLocation()
190 186
      */
191
-    public function getFileLocation($id)
192
-    {
187
+    public function getFileLocation($id) {
193 188
         $location = $this->mets->xpath('./mets:fileSec/mets:fileGrp/mets:file[@ID="' . $id . '"]/mets:FLocat[@LOCTYPE="URL"]');
194 189
         if (
195 190
             !empty($id)
@@ -206,8 +201,7 @@  discard block
 block discarded – undo
206 201
      * {@inheritDoc}
207 202
      * @see \Kitodo\Dlf\Common\Document::getFileMimeType()
208 203
      */
209
-    public function getFileMimeType($id)
210
-    {
204
+    public function getFileMimeType($id) {
211 205
         $mimetype = $this->mets->xpath('./mets:fileSec/mets:fileGrp/mets:file[@ID="' . $id . '"]/@MIMETYPE');
212 206
         if (
213 207
             !empty($id)
@@ -224,8 +218,7 @@  discard block
 block discarded – undo
224 218
      * {@inheritDoc}
225 219
      * @see \Kitodo\Dlf\Common\Document::getLogicalStructure()
226 220
      */
227
-    public function getLogicalStructure($id, $recursive = false)
228
-    {
221
+    public function getLogicalStructure($id, $recursive = false) {
229 222
         $details = [];
230 223
         // Is the requested logical unit already loaded?
231 224
         if (
@@ -265,8 +258,7 @@  discard block
 block discarded – undo
265 258
      *
266 259
      * @return array Array of the element's id, label, type and physical page indexes/mptr link
267 260
      */
268
-    protected function getLogicalStructureInfo(\SimpleXMLElement $structure, $recursive = false)
269
-    {
261
+    protected function getLogicalStructureInfo(\SimpleXMLElement $structure, $recursive = false) {
270 262
         // Get attributes.
271 263
         foreach ($structure->attributes() as $attribute => $value) {
272 264
             $attributes[$attribute] = (string) $value;
@@ -356,8 +348,7 @@  discard block
 block discarded – undo
356 348
      * {@inheritDoc}
357 349
      * @see \Kitodo\Dlf\Common\Document::getMetadata()
358 350
      */
359
-    public function getMetadata($id, $cPid = 0)
360
-    {
351
+    public function getMetadata($id, $cPid = 0) {
361 352
         // Make sure $cPid is a non-negative integer.
362 353
         $cPid = max(intval($cPid), 0);
363 354
         // If $cPid is not given, try to get it elsewhere.
@@ -641,8 +632,7 @@  discard block
 block discarded – undo
641 632
      * {@inheritDoc}
642 633
      * @see \Kitodo\Dlf\Common\Document::getRawText()
643 634
      */
644
-    public function getRawText($id)
645
-    {
635
+    public function getRawText($id) {
646 636
         $rawText = '';
647 637
         // Get text from raw text array if available.
648 638
         if (!empty($this->rawTextArray[$id])) {
@@ -660,8 +650,7 @@  discard block
 block discarded – undo
660 650
      * {@inheritDoc}
661 651
      * @see Document::getStructureDepth()
662 652
      */
663
-    public function getStructureDepth($logId)
664
-    {
653
+    public function getStructureDepth($logId) {
665 654
         $ancestors = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@ID="' . $logId . '"]/ancestor::*');
666 655
         if (!empty($ancestors)) {
667 656
             return count($ancestors);
@@ -674,8 +663,7 @@  discard block
 block discarded – undo
674 663
      * {@inheritDoc}
675 664
      * @see \Kitodo\Dlf\Common\Document::init()
676 665
      */
677
-    protected function init()
678
-    {
666
+    protected function init() {
679 667
         // Get METS node from XML file.
680 668
         $this->registerNamespaces($this->xml);
681 669
         $mets = $this->xml->xpath('//mets:mets');
@@ -692,8 +680,7 @@  discard block
 block discarded – undo
692 680
      * {@inheritDoc}
693 681
      * @see \Kitodo\Dlf\Common\Document::loadLocation()
694 682
      */
695
-    protected function loadLocation($location)
696
-    {
683
+    protected function loadLocation($location) {
697 684
         $fileResource = GeneralUtility::getUrl($location);
698 685
         if ($fileResource !== false) {
699 686
             // Turn off libxml's error logging.
@@ -720,8 +707,7 @@  discard block
 block discarded – undo
720 707
      * {@inheritDoc}
721 708
      * @see \Kitodo\Dlf\Common\Document::ensureHasFulltextIsSet()
722 709
      */
723
-    protected function ensureHasFulltextIsSet()
724
-    {
710
+    protected function ensureHasFulltextIsSet() {
725 711
         // Are the fileGrps already loaded?
726 712
         if (!$this->fileGrpsLoaded) {
727 713
             $this->_getFileGrps();
@@ -732,8 +718,7 @@  discard block
 block discarded – undo
732 718
      * {@inheritDoc}
733 719
      * @see Document::getParentDocumentUid()
734 720
      */
735
-    protected function getParentDocumentUidForSaving($pid, $core)
736
-    {
721
+    protected function getParentDocumentUidForSaving($pid, $core) {
737 722
         $partof = 0;
738 723
         // Get the closest ancestor of the current document which has a MPTR child.
739 724
         $parentMptr = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@ID="' . $this->_getToplevelId() . '"]/ancestor::mets:div[./mets:mptr][1]/mets:mptr');
@@ -756,8 +741,7 @@  discard block
 block discarded – undo
756 741
      * {@inheritDoc}
757 742
      * @see Document::setPreloadedDocument()
758 743
      */
759
-    protected function setPreloadedDocument($preloadedDocument)
760
-    {
744
+    protected function setPreloadedDocument($preloadedDocument) {
761 745
 
762 746
         if ($preloadedDocument instanceof \SimpleXMLElement) {
763 747
             $this->xml = $preloadedDocument;
@@ -770,8 +754,7 @@  discard block
 block discarded – undo
770 754
      * {@inheritDoc}
771 755
      * @see Document::getDocument()
772 756
      */
773
-    protected function getDocument()
774
-    {
757
+    protected function getDocument() {
775 758
         return $this->mets;
776 759
     }
777 760
 
@@ -782,8 +765,7 @@  discard block
 block discarded – undo
782 765
      *
783 766
      * @return int The PID of the metadata definitions
784 767
      */
785
-    protected function _getCPid()
786
-    {
768
+    protected function _getCPid() {
787 769
         return $this->cPid;
788 770
     }
789 771
 
@@ -794,8 +776,7 @@  discard block
 block discarded – undo
794 776
      *
795 777
      * @return array Array of dmdSecs with their IDs as array key
796 778
      */
797
-    protected function _getDmdSec()
798
-    {
779
+    protected function _getDmdSec() {
799 780
         if (!$this->dmdSecLoaded) {
800 781
             // Get available data formats.
801 782
             $this->loadFormats();
@@ -833,8 +814,7 @@  discard block
 block discarded – undo
833 814
      *
834 815
      * @return array Array of file use groups with file IDs
835 816
      */
836
-    protected function _getFileGrps()
837
-    {
817
+    protected function _getFileGrps() {
838 818
         if (!$this->fileGrpsLoaded) {
839 819
             // Get configured USE attributes.
840 820
             $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][self::$extKey]);
@@ -879,8 +859,7 @@  discard block
 block discarded – undo
879 859
      * {@inheritDoc}
880 860
      * @see \Kitodo\Dlf\Common\Document::prepareMetadataArray()
881 861
      */
882
-    protected function prepareMetadataArray($cPid)
883
-    {
862
+    protected function prepareMetadataArray($cPid) {
884 863
         $ids = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@DMDID]/@ID');
885 864
         // Get all logical structure nodes with metadata.
886 865
         if (!empty($ids)) {
@@ -898,8 +877,7 @@  discard block
 block discarded – undo
898 877
      *
899 878
      * @return \SimpleXMLElement The XML's METS part as \SimpleXMLElement object
900 879
      */
901
-    protected function _getMets()
902
-    {
880
+    protected function _getMets() {
903 881
         return $this->mets;
904 882
     }
905 883
 
@@ -907,8 +885,7 @@  discard block
 block discarded – undo
907 885
      * {@inheritDoc}
908 886
      * @see \Kitodo\Dlf\Common\Document::_getPhysicalStructure()
909 887
      */
910
-    protected function _getPhysicalStructure()
911
-    {
888
+    protected function _getPhysicalStructure() {
912 889
         // Is there no physical structure array yet?
913 890
         if (!$this->physicalStructureLoaded) {
914 891
             // Does the document have a structMap node of type "PHYSICAL"?
@@ -968,8 +945,7 @@  discard block
 block discarded – undo
968 945
      * {@inheritDoc}
969 946
      * @see \Kitodo\Dlf\Common\Document::_getSmLinks()
970 947
      */
971
-    protected function _getSmLinks()
972
-    {
948
+    protected function _getSmLinks() {
973 949
         if (!$this->smLinksLoaded) {
974 950
             $smLinks = $this->mets->xpath('./mets:structLink/mets:smLink');
975 951
             if (!empty($smLinks)) {
@@ -987,8 +963,7 @@  discard block
 block discarded – undo
987 963
      * {@inheritDoc}
988 964
      * @see \Kitodo\Dlf\Common\Document::_getThumbnail()
989 965
      */
990
-    protected function _getThumbnail($forceReload = false)
991
-    {
966
+    protected function _getThumbnail($forceReload = false) {
992 967
         if (
993 968
             !$this->thumbnailLoaded
994 969
             || $forceReload
@@ -1061,8 +1036,7 @@  discard block
 block discarded – undo
1061 1036
      * {@inheritDoc}
1062 1037
      * @see \Kitodo\Dlf\Common\Document::_getToplevelId()
1063 1038
      */
1064
-    protected function _getToplevelId()
1065
-    {
1039
+    protected function _getToplevelId() {
1066 1040
         if (empty($this->toplevelId)) {
1067 1041
             // Get all logical structure nodes with metadata, but without associated METS-Pointers.
1068 1042
             $divs = $this->mets->xpath('./mets:structMap[@TYPE="LOGICAL"]//mets:div[@DMDID and not(./mets:mptr)]');
@@ -1094,8 +1068,7 @@  discard block
 block discarded – undo
1094 1068
      *
1095 1069
      * @return array Properties to be serialized
1096 1070
      */
1097
-    public function __sleep()
1098
-    {
1071
+    public function __sleep() {
1099 1072
         // \SimpleXMLElement objects can't be serialized, thus save the XML as string for serialization
1100 1073
         $this->asXML = $this->xml->asXML();
1101 1074
         return ['uid', 'pid', 'recordId', 'parentId', 'asXML'];
@@ -1108,8 +1081,7 @@  discard block
 block discarded – undo
1108 1081
      *
1109 1082
      * @return string String representing the METS object
1110 1083
      */
1111
-    public function __toString()
1112
-    {
1084
+    public function __toString() {
1113 1085
         $xml = new \DOMDocument('1.0', 'utf-8');
1114 1086
         $xml->appendChild($xml->importNode(dom_import_simplexml($this->mets), true));
1115 1087
         $xml->formatOutput = true;
@@ -1124,8 +1096,7 @@  discard block
 block discarded – undo
1124 1096
      *
1125 1097
      * @return void
1126 1098
      */
1127
-    public function __wakeup()
1128
-    {
1099
+    public function __wakeup() {
1129 1100
         // Turn off libxml's error logging.
1130 1101
         $libxmlErrors = libxml_use_internal_errors(true);
1131 1102
         // Reload XML from string.
Please login to merge, or discard this patch.