| Conditions | 9 |
| Paths | 38 |
| Total Lines | 97 |
| Code Lines | 63 |
| 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 |
||
| 54 | public function mainAction(ServerRequestInterface $request): ResponseInterface |
||
| 55 | { |
||
| 56 | $backendUser = $this->getBackendUser(); |
||
| 57 | $queryParams = $request->getQueryParams(); |
||
| 58 | $postValues = $request->getParsedBody(); |
||
| 59 | $moduleState = $backendUser->uc['moduleData']['system_config'] ?? []; |
||
| 60 | |||
| 61 | $configurationProviderIdentifier = (string)($queryParams['tree'] ?? $moduleState['tree'] ?? ''); |
||
| 62 | |||
| 63 | if ($configurationProviderIdentifier === '' |
||
| 64 | && $this->configurationProviderRegistry->getFirstProvider() !== null |
||
| 65 | ) { |
||
| 66 | $configurationProviderIdentifier = $this->configurationProviderRegistry->getFirstProvider()->getIdentifier(); |
||
| 67 | } |
||
| 68 | |||
| 69 | if (!$this->configurationProviderRegistry->hasProvider($configurationProviderIdentifier)) { |
||
| 70 | throw new \InvalidArgumentException( |
||
| 71 | 'No provider found for identifier: ' . $configurationProviderIdentifier, |
||
| 72 | 1606306196 |
||
| 73 | ); |
||
| 74 | } |
||
| 75 | |||
| 76 | $configurationProvider = $this->configurationProviderRegistry->getProvider($configurationProviderIdentifier); |
||
| 77 | $moduleState['tree'] = $configurationProviderIdentifier; |
||
| 78 | |||
| 79 | $configurationArray = $configurationProvider->getConfiguration(); |
||
| 80 | |||
| 81 | // Search string given or regex search enabled? |
||
| 82 | $searchString = (string)($postValues['searchString'] ? trim($postValues['searchString']) : ''); |
||
| 83 | $moduleState['regexSearch'] = (bool)($postValues['regexSearch'] ?? $moduleState['regexSearch'] ?? false); |
||
| 84 | |||
| 85 | // Prepare array renderer class, apply search and expand / collapse states |
||
| 86 | $route = GeneralUtility::makeInstance(Router::class)->match(GeneralUtility::_GP('route')); |
||
| 87 | $arrayBrowser = GeneralUtility::makeInstance(ArrayBrowser::class, $route); |
||
| 88 | $arrayBrowser->regexMode = $moduleState['regexSearch']; |
||
| 89 | $node = $queryParams['node']; |
||
| 90 | if ($searchString) { |
||
| 91 | $arrayBrowser->depthKeys = $arrayBrowser->getSearchKeys($configurationArray, '', $searchString, []); |
||
| 92 | } elseif (is_array($node)) { |
||
| 93 | $newExpandCollapse = $arrayBrowser->depthKeys($node, $moduleState['node_' . $configurationProviderIdentifier]); |
||
| 94 | $arrayBrowser->depthKeys = $newExpandCollapse; |
||
| 95 | $moduleState['node_' . $configurationProviderIdentifier] = $newExpandCollapse; |
||
| 96 | } else { |
||
| 97 | $arrayBrowser->depthKeys = $moduleState['node_' . $configurationProviderIdentifier] ?? []; |
||
| 98 | } |
||
| 99 | |||
| 100 | // Store new state |
||
| 101 | $backendUser->uc['moduleData']['system_config'] = $moduleState; |
||
| 102 | $backendUser->writeUC(); |
||
| 103 | |||
| 104 | // Render main body |
||
| 105 | $view = GeneralUtility::makeInstance(StandaloneView::class); |
||
| 106 | $view->getRequest()->setControllerExtensionName('lowlevel'); |
||
| 107 | $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName( |
||
| 108 | 'EXT:lowlevel/Resources/Private/Templates/Backend/Configuration.html' |
||
| 109 | )); |
||
| 110 | $view->assignMultiple([ |
||
| 111 | 'treeName' => $configurationProvider->getLabel(), |
||
| 112 | 'searchString' => $searchString, |
||
| 113 | 'regexSearch' => $moduleState['regexSearch'], |
||
| 114 | 'tree' => $arrayBrowser->tree($configurationArray, ''), |
||
| 115 | ]); |
||
| 116 | |||
| 117 | // Prepare module setup |
||
| 118 | $moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class); |
||
| 119 | $moduleTemplate->setContent($view->render()); |
||
| 120 | $moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Lowlevel/ConfigurationView'); |
||
| 121 | |||
| 122 | // Shortcut in doc header |
||
| 123 | $shortcutButton = $moduleTemplate->getDocHeaderComponent()->getButtonBar()->makeShortcutButton(); |
||
| 124 | $shortcutButton->setModuleName('system_config') |
||
| 125 | ->setDisplayName($configurationProvider->getLabel()) |
||
| 126 | ->setArguments([ |
||
| 127 | 'route' => $request->getQueryParams()['route'], |
||
| 128 | 'tree' => $configurationProviderIdentifier, |
||
| 129 | ]); |
||
| 130 | $moduleTemplate->getDocHeaderComponent()->getButtonBar()->addButton($shortcutButton); |
||
| 131 | |||
| 132 | // Main drop down in doc header |
||
| 133 | $menu = $moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu(); |
||
| 134 | $menu->setIdentifier('tree'); |
||
| 135 | |||
| 136 | foreach ($this->configurationProviderRegistry->getProviders() as $provider) { |
||
| 137 | $menuItem = $menu->makeMenuItem(); |
||
| 138 | $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); |
||
| 139 | $menuItem |
||
| 140 | ->setHref((string)$uriBuilder->buildUriFromRoute('system_config', ['tree' => $provider->getIdentifier()])) |
||
| 141 | ->setTitle($provider->getLabel()); |
||
| 142 | if ($configurationProvider === $provider) { |
||
| 143 | $menuItem->setActive(true); |
||
| 144 | } |
||
| 145 | $menu->addMenuItem($menuItem); |
||
| 146 | } |
||
| 147 | |||
| 148 | $moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu); |
||
| 149 | |||
| 150 | return new HtmlResponse($moduleTemplate->renderContent()); |
||
| 151 | } |
||
| 162 |