We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 10 |
| Paths | 384 |
| Total Lines | 113 |
| Code Lines | 79 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 96 | public function checkMetadataFormats(&$params, &$pObj) { |
||
|
2 ignored issues
–
show
|
|||
| 97 | $nsDefined = [ |
||
| 98 | 'MODS' => FALSE, |
||
| 99 | 'TEIHDR' => FALSE, |
||
| 100 | 'ALTO' => FALSE, |
||
| 101 | 'IIIF1' => FALSE, |
||
| 102 | 'IIIF2' => FALSE, |
||
| 103 | 'IIIF3' => FALSE |
||
| 104 | ]; |
||
| 105 | |||
| 106 | /** @var QueryBuilder $queryBuilder */ |
||
| 107 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
| 108 | ->getQueryBuilderForTable('tx_dlf_collections'); |
||
| 109 | |||
| 110 | // Check existing format specifications. |
||
| 111 | $result = $queryBuilder |
||
| 112 | ->select('tx_dlf_formats.type AS type') |
||
| 113 | ->from('tx_dlf_formats') |
||
| 114 | ->where( |
||
| 115 | '1=1', |
||
| 116 | Helper::whereExpression('tx_dlf_formats') |
||
| 117 | ) |
||
| 118 | ->execute(); |
||
| 119 | |||
| 120 | while ($resArray = $result->fetch()) { |
||
| 121 | $nsDefined[$resArray['type']] = TRUE; |
||
| 122 | } |
||
| 123 | // Build data array. |
||
| 124 | $data = []; |
||
| 125 | // Add MODS namespace. |
||
| 126 | if (!$nsDefined['MODS']) { |
||
| 127 | $data['tx_dlf_formats'][uniqid('NEW')] = [ |
||
| 128 | 'pid' => 0, |
||
| 129 | 'type' => 'MODS', |
||
| 130 | 'root' => 'mods', |
||
| 131 | 'namespace' => 'http://www.loc.gov/mods/v3', |
||
| 132 | 'class' => 'Kitodo\\\\Dlf\\\\Format\\\\Mods' |
||
| 133 | ]; |
||
| 134 | } |
||
| 135 | // Add TEIHDR namespace. |
||
| 136 | if (!$nsDefined['TEIHDR']) { |
||
| 137 | $data['tx_dlf_formats'][uniqid('NEW')] = [ |
||
| 138 | 'pid' => 0, |
||
| 139 | 'type' => 'TEIHDR', |
||
| 140 | 'root' => 'teiHeader', |
||
| 141 | 'namespace' => 'http://www.tei-c.org/ns/1.0', |
||
| 142 | 'class' => 'Kitodo\\\\Dlf\\\\Format\\\\TeiHeader' |
||
| 143 | ]; |
||
| 144 | } |
||
| 145 | // Add ALTO namespace. |
||
| 146 | if (!$nsDefined['ALTO']) { |
||
| 147 | $data['tx_dlf_formats'][uniqid('NEW')] = [ |
||
| 148 | 'pid' => 0, |
||
| 149 | 'type' => 'ALTO', |
||
| 150 | 'root' => 'alto', |
||
| 151 | 'namespace' => 'http://www.loc.gov/standards/alto/ns-v2#', |
||
| 152 | 'class' => 'Kitodo\\\\Dlf\\\\Format\\\\Alto' |
||
| 153 | ]; |
||
| 154 | } |
||
| 155 | // Add IIIF Metadata API 1 context |
||
| 156 | if (!$nsDefined['IIIF1']) { |
||
| 157 | $data['tx_dlf_formats'][uniqid('NEW')] = array ( |
||
| 158 | 'pid' => 0, |
||
| 159 | 'type' => 'IIIF1', |
||
| 160 | 'root' => 'IIIF1', |
||
| 161 | 'namespace' => 'http://www.shared-canvas.org/ns/context.json', |
||
| 162 | 'class' => '' |
||
| 163 | ); |
||
| 164 | } |
||
| 165 | // Add IIIF Presentation 2 context |
||
| 166 | if (!$nsDefined['IIIF2']) { |
||
| 167 | $data['tx_dlf_formats'][uniqid('NEW')] = array ( |
||
| 168 | 'pid' => 0, |
||
| 169 | 'type' => 'IIIF2', |
||
| 170 | 'root' => 'IIIF2', |
||
| 171 | 'namespace' => 'http://iiif.io/api/presentation/2/context.json', |
||
| 172 | 'class' => '' |
||
| 173 | ); |
||
| 174 | } |
||
| 175 | // Add IIIF Presentation 3 context |
||
| 176 | if (!$nsDefined['IIIF3']) { |
||
| 177 | $data['tx_dlf_formats'][uniqid('NEW')] = array ( |
||
| 178 | 'pid' => 0, |
||
| 179 | 'type' => 'IIIF3', |
||
| 180 | 'root' => 'IIIF3', |
||
| 181 | 'namespace' => 'http://iiif.io/api/presentation/3/context.json', |
||
| 182 | 'class' => '' |
||
| 183 | ); |
||
| 184 | } |
||
| 185 | if (!empty($data)) { |
||
| 186 | // Process changes. |
||
| 187 | $substUid = Helper::processDBasAdmin($data); |
||
| 188 | if (!empty($substUid)) { |
||
| 189 | Helper::addMessage( |
||
| 190 | $GLOBALS['LANG']->getLL('metadataFormats.nsCreatedMsg'), |
||
| 191 | $GLOBALS['LANG']->getLL('metadataFormats.nsCreated'), |
||
| 192 | \TYPO3\CMS\Core\Messaging\FlashMessage::INFO |
||
| 193 | ); |
||
| 194 | } else { |
||
| 195 | Helper::addMessage( |
||
| 196 | $GLOBALS['LANG']->getLL('metadataFormats.nsNotCreatedMsg'), |
||
| 197 | $GLOBALS['LANG']->getLL('metadataFormats.nsNotCreated'), |
||
| 198 | \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR |
||
| 199 | ); |
||
| 200 | } |
||
| 201 | } else { |
||
| 202 | Helper::addMessage( |
||
| 203 | $GLOBALS['LANG']->getLL('metadataFormats.nsOkayMsg'), |
||
| 204 | $GLOBALS['LANG']->getLL('metadataFormats.nsOkay'), |
||
| 205 | \TYPO3\CMS\Core\Messaging\FlashMessage::OK |
||
| 206 | ); |
||
| 207 | } |
||
| 208 | return Helper::renderFlashMessages(); |
||
| 209 | } |
||
| 225 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.