We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Total Complexity | 71 |
| Total Lines | 260 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Complex classes like MetadataController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use MetadataController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 24 | class MetadataController extends AbstractController |
||
| 25 | { |
||
| 26 | public $prefixId = 'tx_dlf'; |
||
| 27 | |||
| 28 | protected $metadataRepository; |
||
| 29 | |||
| 30 | protected $collectionRepository; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param CollectionRepository $collectionRepository |
||
| 34 | */ |
||
| 35 | public function injectCollectionRepository(CollectionRepository $collectionRepository) |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param MetadataRepository $metadataRepository |
||
| 42 | */ |
||
| 43 | public function injectMetadataRepository(MetadataRepository $metadataRepository) |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @return string|void |
||
| 50 | */ |
||
| 51 | public function mainAction() |
||
| 52 | { |
||
| 53 | $this->cObj = $this->configurationManager->getContentObject(); |
||
|
|
|||
| 54 | |||
| 55 | // Load current document. |
||
| 56 | $this->loadDocument($this->requestData); |
||
| 57 | if ( |
||
| 58 | $this->document === null |
||
| 59 | || $this->document->getDoc() === null |
||
| 60 | ) { |
||
| 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->document->getDoc() instanceof IiifManifest; |
||
| 82 | $metadata = []; |
||
| 83 | if ($this->settings['rootline'] < 2) { |
||
| 84 | // Get current structure's @ID. |
||
| 85 | $ids = []; |
||
| 86 | if (!empty($this->document->getDoc()->physicalStructure[$this->requestData['page']]) && !empty($this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[$this->requestData['page']]])) { |
||
| 87 | foreach ($this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[$this->requestData['page']]] as $logId) { |
||
| 88 | $count = $this->document->getDoc()->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->document->getDoc()->getManifestMetadata($sid, $this->settings['storagePid']); |
||
| 100 | } else { |
||
| 101 | $data = $this->document->getDoc()->getMetadata($sid, $this->settings['storagePid']); |
||
| 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->document->getDoc()->getManifestMetadata($sid, $this->settings['storagePid']); |
||
| 115 | } else { |
||
| 116 | $data = $this->document->getDoc()->getMetadata($sid, $this->settings['storagePid']); |
||
| 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->document->getDoc()->toplevelId)) { |
||
| 128 | $data = $useOriginalIiifManifestMetadata ? $this->document->getDoc()->getManifestMetadata($this->document->getDoc()->toplevelId, $this->settings['storagePid']) : $this->document->getDoc()->getTitleData($this->settings['storagePid']); |
||
| 129 | $data['_id'] = $this->document->getDoc()->toplevelId; |
||
| 130 | array_unshift($metadata, $data); |
||
| 131 | } |
||
| 132 | if (empty($metadata)) { |
||
| 133 | $this->logger->warning('No metadata found for document with UID ' . $this->document->getUid()); |
||
| 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 | } |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Prepares the metadata array for output |
||
| 150 | * |
||
| 151 | * @access protected |
||
| 152 | * |
||
| 153 | * @param array $metadataArray: The metadata array |
||
| 154 | * @param bool $useOriginalIiifManifestMetadata: Output IIIF metadata as simple key/value pairs? |
||
| 155 | * |
||
| 156 | * @return string The metadata array ready for output |
||
| 157 | */ |
||
| 158 | protected function printMetadata(array $metadataArray, $useOriginalIiifManifestMetadata = false) |
||
| 284 | |||
| 285 | } |
||
| 288 |