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