We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 28 |
| 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 |
||
| 51 | public function mainAction() |
||
| 52 | { |
||
| 53 | $requestData = GeneralUtility::_GPmerged('tx_dlf'); |
||
| 54 | unset($requestData['__referrer'], $requestData['__trustedProperties']); |
||
| 55 | |||
| 56 | $this->cObj = $this->configurationManager->getContentObject(); |
||
|
|
|||
| 57 | |||
| 58 | // Load current document. |
||
| 59 | $this->loadDocument($requestData); |
||
| 60 | if ($this->doc === null) { |
||
| 61 | // Quit without doing anything if required variables are not set. |
||
| 62 | return ''; |
||
| 63 | } else { |
||
| 64 | // Set default values if not set. |
||
| 65 | if (!isset($this->settings['rootline'])) { |
||
| 66 | $this->settings['rootline'] = 0; |
||
| 67 | } |
||
| 68 | if (!isset($this->settings['originalIiifMetadata'])) { |
||
| 69 | $this->settings['originalIiifMetadata'] = 0; |
||
| 70 | } |
||
| 71 | if (!isset($this->settings['displayIiifDescription'])) { |
||
| 72 | $this->settings['displayIiifDescription'] = 1; |
||
| 73 | } |
||
| 74 | if (!isset($this->settings['displayIiifRights'])) { |
||
| 75 | $this->settings['displayIiifRights'] = 1; |
||
| 76 | } |
||
| 77 | if (!isset($this->settings['displayIiifLinks'])) { |
||
| 78 | $this->settings['displayIiifLinks'] = 1; |
||
| 79 | } |
||
| 80 | } |
||
| 81 | $useOriginalIiifManifestMetadata = $this->settings['originalIiifMetadata'] == 1 && $this->doc instanceof IiifManifest; |
||
| 82 | $metadata = []; |
||
| 83 | if ($this->settings['rootline'] < 2) { |
||
| 84 | // Get current structure's @ID. |
||
| 85 | $ids = []; |
||
| 86 | if (!empty($this->doc->physicalStructure[$requestData['page']]) && !empty($this->doc->smLinks['p2l'][$this->doc->physicalStructure[$requestData['page']]])) { |
||
| 87 | foreach ($this->doc->smLinks['p2l'][$this->doc->physicalStructure[$requestData['page']]] as $logId) { |
||
| 88 | $count = $this->doc->getStructureDepth($logId); |
||
| 89 | $ids[$count][] = $logId; |
||
| 90 | } |
||
| 91 | } |
||
| 92 | ksort($ids); |
||
| 93 | reset($ids); |
||
| 94 | // Check if we should display all metadata up to the root. |
||
| 95 | if ($this->settings['rootline'] == 1) { |
||
| 96 | foreach ($ids as $id) { |
||
| 97 | foreach ($id as $sid) { |
||
| 98 | if ($useOriginalIiifManifestMetadata) { |
||
| 99 | $data = $this->doc->getManifestMetadata($sid, $this->settings['pages']); |
||
| 100 | } else { |
||
| 101 | $data = $this->doc->getMetadata($sid, $this->settings['pages']); |
||
| 102 | } |
||
| 103 | if (!empty($data)) { |
||
| 104 | $data['_id'] = $sid; |
||
| 105 | $metadata[] = $data; |
||
| 106 | } |
||
| 107 | } |
||
| 108 | } |
||
| 109 | } else { |
||
| 110 | $id = array_pop($ids); |
||
| 111 | if (is_array($id)) { |
||
| 112 | foreach ($id as $sid) { |
||
| 113 | if ($useOriginalIiifManifestMetadata) { |
||
| 114 | $data = $this->doc->getManifestMetadata($sid, $this->settings['pages']); |
||
| 115 | } else { |
||
| 116 | $data = $this->doc->getMetadata($sid, $this->settings['pages']); |
||
| 117 | } |
||
| 118 | if (!empty($data)) { |
||
| 119 | $data['_id'] = $sid; |
||
| 120 | $metadata[] = $data; |
||
| 121 | } |
||
| 122 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 | } |
||
| 126 | // Get titledata? |
||
| 127 | if (empty($metadata) || ($this->settings['rootline'] == 1 && $metadata[0]['_id'] != $this->doc->toplevelId)) { |
||
| 128 | $data = $useOriginalIiifManifestMetadata ? $this->doc->getManifestMetadata($this->doc->toplevelId, $this->settings['pages']) : $this->doc->getTitleData($this->settings['pages']); |
||
| 129 | $data['_id'] = $this->doc->toplevelId; |
||
| 130 | array_unshift($metadata, $data); |
||
| 131 | } |
||
| 132 | if (empty($metadata)) { |
||
| 133 | $this->logger->warning('No metadata found for document with UID ' . $this->doc->uid); |
||
|
1 ignored issue
–
show
|
|||
| 134 | return ''; |
||
| 135 | } |
||
| 136 | ksort($metadata); |
||
| 137 | // Get hook objects. |
||
| 138 | $this->hookObjects = Helper::getHookObjects($this->scriptRelPath); |
||
| 139 | // Hook for getting a customized title bar (requested by SBB). |
||
| 140 | foreach ($this->hookObjects as $hookObj) { |
||
| 141 | if (method_exists($hookObj, 'main_customizeTitleBarGetCustomTemplate')) { |
||
| 142 | $hookObj->main_customizeTitleBarGetCustomTemplate($this, $metadata); |
||
| 143 | } |
||
| 144 | } |
||
| 145 | $this->printMetadata($metadata, $useOriginalIiifManifestMetadata); |
||
| 146 | } |
||
| 311 |