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 |
||
| 90 | public function mainAction() |
||
| 91 | { |
||
| 92 | $this->cObj = $this->configurationManager->getContentObject(); |
||
|
|
|||
| 93 | |||
| 94 | // Load current document. |
||
| 95 | $this->loadDocument($this->requestData); |
||
| 96 | if ( |
||
| 97 | $this->document === null |
||
| 98 | || $this->document->getDoc() === null |
||
| 99 | ) { |
||
| 100 | // Quit without doing anything if required variables are not set. |
||
| 101 | return ''; |
||
| 102 | } else { |
||
| 103 | // Set default values if not set. |
||
| 104 | if (!isset($this->settings['rootline'])) { |
||
| 105 | $this->settings['rootline'] = 0; |
||
| 106 | } |
||
| 107 | if (!isset($this->settings['originalIiifMetadata'])) { |
||
| 108 | $this->settings['originalIiifMetadata'] = 0; |
||
| 109 | } |
||
| 110 | if (!isset($this->settings['displayIiifDescription'])) { |
||
| 111 | $this->settings['displayIiifDescription'] = 1; |
||
| 112 | } |
||
| 113 | if (!isset($this->settings['displayIiifRights'])) { |
||
| 114 | $this->settings['displayIiifRights'] = 1; |
||
| 115 | } |
||
| 116 | if (!isset($this->settings['displayIiifLinks'])) { |
||
| 117 | $this->settings['displayIiifLinks'] = 1; |
||
| 118 | } |
||
| 119 | } |
||
| 120 | $useOriginalIiifManifestMetadata = $this->settings['originalIiifMetadata'] == 1 && $this->document->getDoc() instanceof IiifManifest; |
||
| 121 | $metadata = []; |
||
| 122 | if ($this->settings['rootline'] < 2) { |
||
| 123 | // Get current structure's @ID. |
||
| 124 | $ids = []; |
||
| 125 | if (!empty($this->document->getDoc()->physicalStructure[$this->requestData['page']]) && !empty($this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[$this->requestData['page']]])) { |
||
| 126 | foreach ($this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[$this->requestData['page']]] as $logId) { |
||
| 127 | $count = $this->document->getDoc()->getStructureDepth($logId); |
||
| 128 | $ids[$count][] = $logId; |
||
| 129 | } |
||
| 130 | } |
||
| 131 | ksort($ids); |
||
| 132 | reset($ids); |
||
| 133 | // Check if we should display all metadata up to the root. |
||
| 134 | if ($this->settings['rootline'] == 1) { |
||
| 135 | foreach ($ids as $id) { |
||
| 136 | foreach ($id as $sid) { |
||
| 137 | if ($useOriginalIiifManifestMetadata) { |
||
| 138 | $data = $this->document->getDoc()->getManifestMetadata($sid, $this->settings['storagePid']); |
||
| 139 | } else { |
||
| 140 | $data = $this->document->getDoc()->getMetadata($sid, $this->settings['storagePid']); |
||
| 141 | } |
||
| 142 | if (!empty($data)) { |
||
| 143 | $data['_id'] = $sid; |
||
| 144 | $metadata[] = $data; |
||
| 145 | } |
||
| 146 | } |
||
| 147 | } |
||
| 148 | } else { |
||
| 149 | $id = array_pop($ids); |
||
| 150 | if (is_array($id)) { |
||
| 151 | foreach ($id as $sid) { |
||
| 152 | if ($useOriginalIiifManifestMetadata) { |
||
| 153 | $data = $this->document->getDoc()->getManifestMetadata($sid, $this->settings['storagePid']); |
||
| 154 | } else { |
||
| 155 | $data = $this->document->getDoc()->getMetadata($sid, $this->settings['storagePid']); |
||
| 156 | } |
||
| 157 | if (!empty($data)) { |
||
| 158 | $data['_id'] = $sid; |
||
| 159 | $metadata[] = $data; |
||
| 160 | } |
||
| 161 | } |
||
| 162 | } |
||
| 163 | } |
||
| 164 | } |
||
| 165 | // Get titledata? |
||
| 166 | if (empty($metadata) || ($this->settings['rootline'] == 1 && $metadata[0]['_id'] != $this->document->getDoc()->toplevelId)) { |
||
| 167 | $data = $useOriginalIiifManifestMetadata ? $this->document->getDoc()->getManifestMetadata($this->document->getDoc()->toplevelId, $this->settings['storagePid']) : $this->document->getDoc()->getTitleData($this->settings['storagePid']); |
||
| 168 | $data['_id'] = $this->document->getDoc()->toplevelId; |
||
| 169 | array_unshift($metadata, $data); |
||
| 170 | } |
||
| 171 | if (empty($metadata)) { |
||
| 172 | $this->logger->warning('No metadata found for document with UID ' . $this->document->getUid()); |
||
| 173 | return ''; |
||
| 174 | } |
||
| 175 | ksort($metadata); |
||
| 176 | // Get hook objects. |
||
| 177 | $this->hookObjects = Helper::getHookObjects($this->scriptRelPath); |
||
| 178 | // Hook for getting a customized title bar (requested by SBB). |
||
| 179 | foreach ($this->hookObjects as $hookObj) { |
||
| 180 | if (method_exists($hookObj, 'main_customizeTitleBarGetCustomTemplate')) { |
||
| 181 | $hookObj->main_customizeTitleBarGetCustomTemplate($this, $metadata); |
||
| 182 | } |
||
| 183 | } |
||
| 184 | $this->printMetadata($metadata, $useOriginalIiifManifestMetadata); |
||
| 185 | } |
||
| 328 |