We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 11 |
| Paths | 768 |
| Total Lines | 123 |
| Code Lines | 83 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 73 | public function checkMetadataFormats() |
||
| 74 | { |
||
| 75 | // We need to do some bootstrapping manually as of TYPO3 9. |
||
| 76 | if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getNumericTypo3Version(), '9.0.0', '>=')) { |
||
| 77 | // Load table configuration array into $GLOBALS['TCA']. |
||
| 78 | ExtensionManagementUtility::loadBaseTca(false); |
||
| 79 | // Get extension configuration from dlf/ext_localconf.php. |
||
| 80 | ExtensionManagementUtility::loadExtLocalconf(false); |
||
| 81 | // Initialize backend user into $GLOBALS['BE_USER']. |
||
| 82 | Bootstrap::initializeBackendUser(); |
||
| 83 | // Initialize backend and ensure authenticated access. |
||
| 84 | Bootstrap::initializeBackendAuthentication(); |
||
| 85 | } |
||
| 86 | |||
| 87 | $nsDefined = [ |
||
| 88 | 'MODS' => false, |
||
| 89 | 'TEIHDR' => false, |
||
| 90 | 'ALTO' => false, |
||
| 91 | 'IIIF1' => false, |
||
| 92 | 'IIIF2' => false, |
||
| 93 | 'IIIF3' => false |
||
| 94 | ]; |
||
| 95 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 96 | ->getQueryBuilderForTable('tx_dlf_formats'); |
||
| 97 | |||
| 98 | // Check existing format specifications. |
||
| 99 | $result = $queryBuilder |
||
| 100 | ->select('tx_dlf_formats.type AS type') |
||
| 101 | ->from('tx_dlf_formats') |
||
| 102 | ->where( |
||
| 103 | '1=1' |
||
| 104 | ) |
||
| 105 | ->execute(); |
||
| 106 | |||
| 107 | while ($resArray = $result->fetch()) { |
||
| 108 | $nsDefined[$resArray['type']] = true; |
||
| 109 | } |
||
| 110 | // Build data array. |
||
| 111 | $data = []; |
||
| 112 | // Add MODS namespace. |
||
| 113 | if (!$nsDefined['MODS']) { |
||
| 114 | $data['tx_dlf_formats'][uniqid('NEW')] = [ |
||
| 115 | 'pid' => 0, |
||
| 116 | 'type' => 'MODS', |
||
| 117 | 'root' => 'mods', |
||
| 118 | 'namespace' => 'http://www.loc.gov/mods/v3', |
||
| 119 | 'class' => 'Kitodo\\Dlf\\Format\\Mods' |
||
| 120 | ]; |
||
| 121 | } |
||
| 122 | // Add TEIHDR namespace. |
||
| 123 | if (!$nsDefined['TEIHDR']) { |
||
| 124 | $data['tx_dlf_formats'][uniqid('NEW')] = [ |
||
| 125 | 'pid' => 0, |
||
| 126 | 'type' => 'TEIHDR', |
||
| 127 | 'root' => 'teiHeader', |
||
| 128 | 'namespace' => 'http://www.tei-c.org/ns/1.0', |
||
| 129 | 'class' => 'Kitodo\\Dlf\\Format\\TeiHeader' |
||
| 130 | ]; |
||
| 131 | } |
||
| 132 | // Add ALTO namespace. |
||
| 133 | if (!$nsDefined['ALTO']) { |
||
| 134 | $data['tx_dlf_formats'][uniqid('NEW')] = [ |
||
| 135 | 'pid' => 0, |
||
| 136 | 'type' => 'ALTO', |
||
| 137 | 'root' => 'alto', |
||
| 138 | 'namespace' => 'http://www.loc.gov/standards/alto/ns-v2#', |
||
| 139 | 'class' => 'Kitodo\\Dlf\\Format\\Alto' |
||
| 140 | ]; |
||
| 141 | } |
||
| 142 | // Add IIIF Metadata API 1 context |
||
| 143 | if (!$nsDefined['IIIF1']) { |
||
| 144 | $data['tx_dlf_formats'][uniqid('NEW')] = [ |
||
| 145 | 'pid' => 0, |
||
| 146 | 'type' => 'IIIF1', |
||
| 147 | 'root' => 'IIIF1', |
||
| 148 | 'namespace' => 'http://www.shared-canvas.org/ns/context.json', |
||
| 149 | 'class' => '' |
||
| 150 | ]; |
||
| 151 | } |
||
| 152 | // Add IIIF Presentation 2 context |
||
| 153 | if (!$nsDefined['IIIF2']) { |
||
| 154 | $data['tx_dlf_formats'][uniqid('NEW')] = [ |
||
| 155 | 'pid' => 0, |
||
| 156 | 'type' => 'IIIF2', |
||
| 157 | 'root' => 'IIIF2', |
||
| 158 | 'namespace' => 'http://iiif.io/api/presentation/2/context.json', |
||
| 159 | 'class' => '' |
||
| 160 | ]; |
||
| 161 | } |
||
| 162 | // Add IIIF Presentation 3 context |
||
| 163 | if (!$nsDefined['IIIF3']) { |
||
| 164 | $data['tx_dlf_formats'][uniqid('NEW')] = [ |
||
| 165 | 'pid' => 0, |
||
| 166 | 'type' => 'IIIF3', |
||
| 167 | 'root' => 'IIIF3', |
||
| 168 | 'namespace' => 'http://iiif.io/api/presentation/3/context.json', |
||
| 169 | 'class' => '' |
||
| 170 | ]; |
||
| 171 | } |
||
| 172 | if (!empty($data)) { |
||
| 173 | // Process changes. |
||
| 174 | $substUid = Helper::processDBasAdmin($data); |
||
| 175 | if (!empty($substUid)) { |
||
| 176 | Helper::addMessage( |
||
| 177 | htmlspecialchars($GLOBALS['LANG']->getLL('metadataFormats.nsCreatedMsg')), |
||
| 178 | htmlspecialchars($GLOBALS['LANG']->getLL('metadataFormats.nsCreated')), |
||
| 179 | \TYPO3\CMS\Core\Messaging\FlashMessage::INFO |
||
| 180 | ); |
||
| 181 | } else { |
||
| 182 | Helper::addMessage( |
||
| 183 | htmlspecialchars($GLOBALS['LANG']->getLL('metadataFormats.nsNotCreatedMsg')), |
||
| 184 | htmlspecialchars($GLOBALS['LANG']->getLL('metadataFormats.nsNotCreated')), |
||
| 185 | \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR |
||
| 186 | ); |
||
| 187 | } |
||
| 188 | } else { |
||
| 189 | Helper::addMessage( |
||
| 190 | htmlspecialchars($GLOBALS['LANG']->getLL('metadataFormats.nsOkayMsg')), |
||
| 191 | htmlspecialchars($GLOBALS['LANG']->getLL('metadataFormats.nsOkay')), |
||
| 192 | \TYPO3\CMS\Core\Messaging\FlashMessage::OK |
||
| 193 | ); |
||
| 194 | } |
||
| 195 | return Helper::renderFlashMessages(); |
||
| 196 | } |
||
| 213 |