We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 29 |
| Paths | 5377 |
| Total Lines | 95 |
| Code Lines | 61 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 76 | public function mainAction() |
||
| 77 | { |
||
| 78 | $this->cObj = $this->configurationManager->getContentObject(); |
||
|
|
|||
| 79 | |||
| 80 | // Load current document. |
||
| 81 | $this->loadDocument($this->requestData); |
||
| 82 | if ( |
||
| 83 | $this->document === null |
||
| 84 | || $this->document->getDoc() === null |
||
| 85 | ) { |
||
| 86 | // Quit without doing anything if required variables are not set. |
||
| 87 | return ''; |
||
| 88 | } else { |
||
| 89 | // Set default values if not set. |
||
| 90 | if (!isset($this->settings['rootline'])) { |
||
| 91 | $this->settings['rootline'] = 0; |
||
| 92 | } |
||
| 93 | if (!isset($this->settings['originalIiifMetadata'])) { |
||
| 94 | $this->settings['originalIiifMetadata'] = 0; |
||
| 95 | } |
||
| 96 | if (!isset($this->settings['displayIiifDescription'])) { |
||
| 97 | $this->settings['displayIiifDescription'] = 1; |
||
| 98 | } |
||
| 99 | if (!isset($this->settings['displayIiifRights'])) { |
||
| 100 | $this->settings['displayIiifRights'] = 1; |
||
| 101 | } |
||
| 102 | if (!isset($this->settings['displayIiifLinks'])) { |
||
| 103 | $this->settings['displayIiifLinks'] = 1; |
||
| 104 | } |
||
| 105 | } |
||
| 106 | $useOriginalIiifManifestMetadata = $this->settings['originalIiifMetadata'] == 1 && $this->document->getDoc() instanceof IiifManifest; |
||
| 107 | $metadata = []; |
||
| 108 | if ($this->settings['rootline'] < 2) { |
||
| 109 | // Get current structure's @ID. |
||
| 110 | $ids = []; |
||
| 111 | if (!empty($this->document->getDoc()->physicalStructure[$this->requestData['page']]) && !empty($this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[$this->requestData['page']]])) { |
||
| 112 | foreach ($this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[$this->requestData['page']]] as $logId) { |
||
| 113 | $count = $this->document->getDoc()->getStructureDepth($logId); |
||
| 114 | $ids[$count][] = $logId; |
||
| 115 | } |
||
| 116 | } |
||
| 117 | ksort($ids); |
||
| 118 | reset($ids); |
||
| 119 | // Check if we should display all metadata up to the root. |
||
| 120 | if ($this->settings['rootline'] == 1) { |
||
| 121 | foreach ($ids as $id) { |
||
| 122 | foreach ($id as $sid) { |
||
| 123 | if ($useOriginalIiifManifestMetadata) { |
||
| 124 | $data = $this->document->getDoc()->getManifestMetadata($sid, $this->settings['storagePid']); |
||
| 125 | } else { |
||
| 126 | $data = $this->document->getDoc()->getMetadata($sid, $this->settings['storagePid']); |
||
| 127 | } |
||
| 128 | if (!empty($data)) { |
||
| 129 | $data['_id'] = $sid; |
||
| 130 | $metadata[] = $data; |
||
| 131 | } |
||
| 132 | } |
||
| 133 | } |
||
| 134 | } else { |
||
| 135 | $id = array_pop($ids); |
||
| 136 | if (is_array($id)) { |
||
| 137 | foreach ($id as $sid) { |
||
| 138 | if ($useOriginalIiifManifestMetadata) { |
||
| 139 | $data = $this->document->getDoc()->getManifestMetadata($sid, $this->settings['storagePid']); |
||
| 140 | } else { |
||
| 141 | $data = $this->document->getDoc()->getMetadata($sid, $this->settings['storagePid']); |
||
| 142 | } |
||
| 143 | if (!empty($data)) { |
||
| 144 | $data['_id'] = $sid; |
||
| 145 | $metadata[] = $data; |
||
| 146 | } |
||
| 147 | } |
||
| 148 | } |
||
| 149 | } |
||
| 150 | } |
||
| 151 | // Get titledata? |
||
| 152 | if (empty($metadata) || ($this->settings['rootline'] == 1 && $metadata[0]['_id'] != $this->document->getDoc()->toplevelId)) { |
||
| 153 | $data = $useOriginalIiifManifestMetadata ? $this->document->getDoc()->getManifestMetadata($this->document->getDoc()->toplevelId, $this->settings['storagePid']) : $this->document->getDoc()->getTitleData($this->settings['storagePid']); |
||
| 154 | $data['_id'] = $this->document->getDoc()->toplevelId; |
||
| 155 | array_unshift($metadata, $data); |
||
| 156 | } |
||
| 157 | if (empty($metadata)) { |
||
| 158 | $this->logger->warning('No metadata found for document with UID ' . $this->document->getUid()); |
||
| 159 | return ''; |
||
| 160 | } |
||
| 161 | ksort($metadata); |
||
| 162 | // Get hook objects. |
||
| 163 | $this->hookObjects = Helper::getHookObjects($this->scriptRelPath); |
||
| 164 | // Hook for getting a customized title bar (requested by SBB). |
||
| 165 | foreach ($this->hookObjects as $hookObj) { |
||
| 166 | if (method_exists($hookObj, 'main_customizeTitleBarGetCustomTemplate')) { |
||
| 167 | $hookObj->main_customizeTitleBarGetCustomTemplate($this, $metadata); |
||
| 168 | } |
||
| 169 | } |
||
| 170 | $this->printMetadata($metadata, $useOriginalIiifManifestMetadata); |
||
| 171 | } |
||
| 316 |