| Conditions | 6 |
| Paths | 6 |
| Total Lines | 60 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 51 | public function getStatus(ServerRequestInterface $request = null): array |
||
| 52 | { |
||
| 53 | $status = []; |
||
| 54 | $extensionsWithComposerDeficit = $this->composerDeficitDetector->getExtensionsWithComposerDeficit(); |
||
| 55 | $languageService = $this->getLanguageService(); |
||
| 56 | $languageService->includeLLFile('EXT:extensionmanager/Resources/Private/Language/locallang.xlf'); |
||
| 57 | $labelPrefix = 'report.status.composerManifest.'; |
||
| 58 | $deficits = [ |
||
| 59 | ComposerDeficitDetector::EXTENSION_COMPOSER_MANIFEST_MISSING => 'composerJsonMissing', |
||
| 60 | ComposerDeficitDetector::EXTENSION_KEY_MISSING => 'extensionKeyMissing' |
||
| 61 | ]; |
||
| 62 | |||
| 63 | $queryParameters = [ |
||
| 64 | 'tx_extensionmanager_tools_extensionmanagerextensionmanager' => [ |
||
| 65 | 'action' => 'list', |
||
| 66 | 'controller' => 'ExtensionComposerStatus', |
||
| 67 | ] |
||
| 68 | ]; |
||
| 69 | |||
| 70 | if ($request !== null) { |
||
| 71 | $queryParameters['tx_extensionmanager_tools_extensionmanagerextensionmanager']['returnUrl'] = |
||
| 72 | $request->getAttribute('normalizedParams')->getRequestUri(); |
||
| 73 | } |
||
| 74 | |||
| 75 | $dispatchAction = 'TYPO3.ModuleMenu.showModule'; |
||
| 76 | $dispatchArgs = [ |
||
| 77 | 'tools_ExtensionmanagerExtensionmanager', |
||
| 78 | '&' . http_build_query($queryParameters) |
||
| 79 | ]; |
||
| 80 | |||
| 81 | foreach ($deficits as $key => $deficit) { |
||
| 82 | $message = ''; |
||
| 83 | $extensionsToReport = count(array_filter($extensionsWithComposerDeficit, static function ($extensionDeficit) use ($key) { |
||
| 84 | return $extensionDeficit === $key; |
||
| 85 | })); |
||
| 86 | |||
| 87 | if ($extensionsToReport) { |
||
| 88 | $linkTitle = $languageService->getLL($labelPrefix . 'update'); |
||
| 89 | $linkAttributes = GeneralUtility::implodeAttributes([ |
||
| 90 | 'href' => '#', |
||
| 91 | 'title' => $linkTitle, |
||
| 92 | 'class' => 'text-decoration-underline', |
||
| 93 | // relies on module 'TYPO3/CMS/Backend/ActionDispatcher' |
||
| 94 | 'data-dispatch-action' => $dispatchAction, |
||
| 95 | 'data-dispatch-args' => GeneralUtility::jsonEncodeForHtmlAttribute($dispatchArgs), |
||
| 96 | ], true); |
||
| 97 | $message = sprintf($languageService->getLL($labelPrefix . $deficit . '.message'), $extensionsToReport) |
||
| 98 | . '<br /><a ' . $linkAttributes . '>' . htmlspecialchars($linkTitle) . '</a>'; |
||
| 99 | } |
||
| 100 | |||
| 101 | $status[] = GeneralUtility::makeInstance( |
||
| 102 | ReportStatus::class, |
||
| 103 | $this->getLanguageService()->getLL($labelPrefix . $deficit), |
||
| 104 | $this->getLanguageService()->getLL($extensionsToReport ? 'status_checkFailed' : 'status_none'), |
||
| 105 | $message, |
||
| 106 | $extensionsToReport ? ReportStatus::WARNING : ReportStatus::OK |
||
| 107 | ); |
||
| 108 | } |
||
| 109 | |||
| 110 | return $status; |
||
| 111 | } |
||
| 118 |