We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 11 |
| Paths | 76 |
| Total Lines | 121 |
| Code Lines | 83 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 171 | public function main(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response) { |
||
| 172 | $this->response = $response; |
||
| 173 | // Initialize module. |
||
| 174 | $this->MCONF = [ |
||
| 175 | 'name' => 'tools_dlfNewTenantModule', |
||
| 176 | 'access' => 'admin' |
||
| 177 | ]; |
||
| 178 | $GLOBALS['BE_USER']->modAccess($this->MCONF, 1); |
||
| 179 | parent::init(); |
||
| 180 | $this->pageInfo = \TYPO3\CMS\Backend\Utility\BackendUtility::readPageAccess($this->id, $this->perms_clause); |
||
| 181 | // Is the user allowed to access this page? |
||
| 182 | $access = is_array($this->pageInfo) && $GLOBALS['BE_USER']->isAdmin(); |
||
| 183 | if ($this->id && $access) { |
||
| 184 | // Check if page is sysfolder. |
||
| 185 | if ($this->pageInfo['doktype'] != 254) { |
||
| 186 | Helper::addMessage( |
||
| 187 | Helper::getMessage('flash.wrongPageTypeMsg'), |
||
| 188 | Helper::getMessage('flash.wrongPageType', TRUE), |
||
| 189 | \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR |
||
| 190 | ); |
||
| 191 | $this->markerArray['CONTENT'] .= Helper::renderFlashMessages(); |
||
| 192 | $this->printContent(); |
||
| 193 | return $this->response; |
||
| 194 | } |
||
| 195 | // Should we do something? |
||
| 196 | if (!empty($this->CMD)) { |
||
| 197 | // Sanitize input... |
||
| 198 | $_method = 'cmd'.ucfirst($this->CMD); |
||
| 199 | // ...and unset to prevent infinite looping. |
||
| 200 | unset ($this->CMD); |
||
| 201 | if (method_exists($this, $_method)) { |
||
| 202 | $this->$_method(); |
||
| 203 | } |
||
| 204 | } |
||
| 205 | // Check for existing structure configuration. |
||
| 206 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 207 | 'uid', |
||
| 208 | 'tx_dlf_structures', |
||
| 209 | 'pid='.intval($this->id) |
||
| 210 | .Helper::whereClause('tx_dlf_structures') |
||
| 211 | ); |
||
| 212 | if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { |
||
| 213 | // Fine. |
||
| 214 | Helper::addMessage( |
||
| 215 | Helper::getMessage('flash.structureOkayMsg'), |
||
| 216 | Helper::getMessage('flash.structureOkay', TRUE), |
||
| 217 | \TYPO3\CMS\Core\Messaging\FlashMessage::OK |
||
| 218 | ); |
||
| 219 | } else { |
||
| 220 | // Configuration missing. |
||
| 221 | $_url = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(['id' => $this->id, 'CMD' => 'addStructure'])); |
||
| 222 | Helper::addMessage( |
||
| 223 | sprintf(Helper::getMessage('flash.structureNotOkayMsg'), $_url), |
||
| 224 | Helper::getMessage('flash.structureNotOkay', TRUE), |
||
| 225 | \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR |
||
| 226 | ); |
||
| 227 | } |
||
| 228 | // Check for existing metadata configuration. |
||
| 229 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 230 | 'uid', |
||
| 231 | 'tx_dlf_metadata', |
||
| 232 | 'pid='.intval($this->id) |
||
| 233 | .Helper::whereClause('tx_dlf_metadata') |
||
| 234 | ); |
||
| 235 | if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { |
||
| 236 | // Fine. |
||
| 237 | Helper::addMessage( |
||
| 238 | Helper::getMessage('flash.metadataOkayMsg'), |
||
| 239 | Helper::getMessage('flash.metadataOkay', TRUE), |
||
| 240 | \TYPO3\CMS\Core\Messaging\FlashMessage::OK |
||
| 241 | ); |
||
| 242 | } else { |
||
| 243 | // Configuration missing. |
||
| 244 | $_url = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(['id' => $this->id, 'CMD' => 'addMetadata'])); |
||
| 245 | Helper::addMessage( |
||
| 246 | sprintf(Helper::getMessage('flash.metadataNotOkayMsg'), $_url), |
||
| 247 | Helper::getMessage('flash.metadataNotOkay', TRUE), |
||
| 248 | \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR |
||
| 249 | ); |
||
| 250 | } |
||
| 251 | // Check for existing Solr core. |
||
| 252 | $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
||
| 253 | 'uid,pid', |
||
| 254 | 'tx_dlf_solrcores', |
||
| 255 | 'pid IN ('.intval($this->id).',0)' |
||
| 256 | .Helper::whereClause('tx_dlf_solrcores') |
||
| 257 | ); |
||
| 258 | if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) { |
||
| 259 | $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result); |
||
| 260 | if ($resArray['pid']) { |
||
| 261 | // Fine. |
||
| 262 | Helper::addMessage( |
||
| 263 | Helper::getMessage('flash.solrcoreOkayMsg'), |
||
| 264 | Helper::getMessage('flash.solrcoreOkay', TRUE), |
||
| 265 | \TYPO3\CMS\Core\Messaging\FlashMessage::OK |
||
| 266 | ); |
||
| 267 | } else { |
||
| 268 | // Default core available, but this is deprecated. |
||
| 269 | $_url = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(['id' => $this->id, 'CMD' => 'addSolrcore'])); |
||
| 270 | Helper::addMessage( |
||
| 271 | sprintf(Helper::getMessage('flash.solrcoreDeprecatedMsg'), $_url), |
||
| 272 | Helper::getMessage('flash.solrcoreDeprecatedOkay', TRUE), |
||
| 273 | \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE |
||
| 274 | ); |
||
| 275 | } |
||
| 276 | } else { |
||
| 277 | // Solr core missing. |
||
| 278 | $_url = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(['id' => $this->id, 'CMD' => 'addSolrcore'])); |
||
| 279 | Helper::addMessage( |
||
| 280 | sprintf(Helper::getMessage('flash.solrcoreMissingMsg'), $_url), |
||
| 281 | Helper::getMessage('flash.solrcoreMissing', TRUE), |
||
| 282 | \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING |
||
| 283 | ); |
||
| 284 | } |
||
| 285 | $this->markerArray['CONTENT'] .= Helper::renderFlashMessages(); |
||
| 286 | } else { |
||
| 287 | // TODO: Ändern! |
||
| 288 | $this->markerArray['CONTENT'] .= 'You are not allowed to access this page or have not selected a page, yet.'; |
||
| 289 | } |
||
| 290 | $this->printContent(); |
||
| 291 | return $this->response; |
||
| 292 | } |
||
| 294 |