| Conditions | 20 |
| Paths | 101 |
| Total Lines | 130 |
| Code Lines | 88 |
| 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 |
||
| 57 | public function saveAction() |
||
| 58 | { |
||
| 59 | $this->checkSecurityToken($this->previousSk, $this->request); |
||
| 60 | |||
| 61 | $configData = $this->config->getConfigData(); |
||
| 62 | $eventMessage = EventMessage::factory(); |
||
| 63 | |||
| 64 | // General |
||
| 65 | $siteLang = $this->request->analyzeString('sitelang'); |
||
| 66 | $siteTheme = $this->request->analyzeString('sitetheme', 'material-blue'); |
||
| 67 | $sessionTimeout = $this->request->analyzeInt('session_timeout', 300); |
||
| 68 | $applicationUrl = $this->request->analyzeString('app_url'); |
||
| 69 | $httpsEnabled = $this->request->analyzeBool('https_enabled', false); |
||
| 70 | $debugEnabled = $this->request->analyzeBool('debug_enabled', false); |
||
| 71 | $maintenanceEnabled = $this->request->analyzeBool('maintenance_enabled', false); |
||
| 72 | $checkUpdatesEnabled = $this->request->analyzeBool('check_updates_enabled', false); |
||
| 73 | $checkNoticesEnabled = $this->request->analyzeBool('check_notices_enabled', false); |
||
| 74 | $encryptSessionEnabled = $this->request->analyzeBool('encrypt_session_enabled', false); |
||
| 75 | |||
| 76 | $configData->setSiteLang($siteLang); |
||
| 77 | $configData->setSiteTheme($siteTheme); |
||
| 78 | $configData->setSessionTimeout($sessionTimeout); |
||
| 79 | $configData->setApplicationUrl($applicationUrl); |
||
| 80 | $configData->setHttpsEnabled($httpsEnabled); |
||
| 81 | $configData->setDebug($debugEnabled); |
||
| 82 | $configData->setMaintenance($maintenanceEnabled); |
||
| 83 | $configData->setCheckUpdates($checkUpdatesEnabled); |
||
| 84 | $configData->setChecknotices($checkNoticesEnabled); |
||
| 85 | $configData->setEncryptSession($encryptSessionEnabled); |
||
| 86 | |||
| 87 | // Events |
||
| 88 | $logEnabled = $this->request->analyzeBool('log_enabled', false); |
||
| 89 | $syslogEnabled = $this->request->analyzeBool('syslog_enabled', false); |
||
| 90 | $remoteSyslogEnabled = $this->request->analyzeBool('remotesyslog_enabled', false); |
||
| 91 | $syslogServer = $this->request->analyzeString('remotesyslog_server'); |
||
| 92 | $syslogPort = $this->request->analyzeInt('remotesyslog_port', 0); |
||
| 93 | |||
| 94 | $configData->setLogEnabled($logEnabled); |
||
| 95 | $configData->setLogEvents($this->request->analyzeArray('log_events', function ($items) { |
||
|
|
|||
| 96 | return ConfigUtil::eventsAdapter($items); |
||
| 97 | }, [])); |
||
| 98 | |||
| 99 | $configData->setSyslogEnabled($syslogEnabled); |
||
| 100 | |||
| 101 | if ($remoteSyslogEnabled) { |
||
| 102 | if (!$syslogServer || !$syslogPort) { |
||
| 103 | return $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('Missing remote syslog parameters')); |
||
| 104 | } |
||
| 105 | |||
| 106 | $configData->setSyslogRemoteEnabled(true); |
||
| 107 | $configData->setSyslogServer($syslogServer); |
||
| 108 | $configData->setSyslogPort($syslogPort); |
||
| 109 | |||
| 110 | if ($configData->isSyslogRemoteEnabled() === false) { |
||
| 111 | $eventMessage->addDescription(__u('Remote syslog enabled')); |
||
| 112 | } |
||
| 113 | } elseif ($remoteSyslogEnabled === false && $configData->isSyslogRemoteEnabled()) { |
||
| 114 | $configData->setSyslogRemoteEnabled(false); |
||
| 115 | |||
| 116 | $eventMessage->addDescription(__u('Remote syslog disabled')); |
||
| 117 | } |
||
| 118 | |||
| 119 | // Proxy |
||
| 120 | $proxyEnabled = $this->request->analyzeBool('proxy_enabled', false); |
||
| 121 | $proxyServer = $this->request->analyzeString('proxy_server'); |
||
| 122 | $proxyPort = $this->request->analyzeInt('proxy_port', 8080); |
||
| 123 | $proxyUser = $this->request->analyzeString('proxy_user'); |
||
| 124 | $proxyPass = $this->request->analyzeEncrypted('proxy_pass'); |
||
| 125 | |||
| 126 | |||
| 127 | // Valores para Proxy |
||
| 128 | if ($proxyEnabled && (!$proxyServer || !$proxyPort)) { |
||
| 129 | return $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('Missing Proxy parameters ')); |
||
| 130 | } |
||
| 131 | |||
| 132 | if ($proxyEnabled) { |
||
| 133 | $configData->setProxyEnabled(true); |
||
| 134 | $configData->setProxyServer($proxyServer); |
||
| 135 | $configData->setProxyPort($proxyPort); |
||
| 136 | $configData->setProxyUser($proxyUser); |
||
| 137 | |||
| 138 | if ($proxyPass !== '***') { |
||
| 139 | $configData->setProxyPass($proxyPass); |
||
| 140 | } |
||
| 141 | |||
| 142 | if ($configData->isProxyEnabled() === false) { |
||
| 143 | $eventMessage->addDescription(__u('Proxy enabled')); |
||
| 144 | } |
||
| 145 | } elseif ($proxyEnabled === false && $configData->isProxyEnabled()) { |
||
| 146 | $configData->setProxyEnabled(false); |
||
| 147 | |||
| 148 | $eventMessage->addDescription(__u('Proxy disabled')); |
||
| 149 | } |
||
| 150 | |||
| 151 | // Autentificación |
||
| 152 | $authBasicEnabled = $this->request->analyzeBool('authbasic_enabled', false); |
||
| 153 | $authBasicAutologinEnabled = $this->request->analyzeBool('authbasicautologin_enabled', false); |
||
| 154 | $authBasicDomain = $this->request->analyzeString('authbasic_domain'); |
||
| 155 | $authSsoDefaultGroup = $this->request->analyzeInt('sso_defaultgroup'); |
||
| 156 | $authSsoDefaultProfile = $this->request->analyzeInt('sso_defaultprofile'); |
||
| 157 | |||
| 158 | // Valores para Autentificación |
||
| 159 | if ($authBasicEnabled) { |
||
| 160 | $configData->setAuthBasicEnabled(true); |
||
| 161 | $configData->setAuthBasicAutoLoginEnabled($authBasicAutologinEnabled); |
||
| 162 | $configData->setAuthBasicDomain($authBasicDomain); |
||
| 163 | $configData->setSsoDefaultGroup($authSsoDefaultGroup); |
||
| 164 | $configData->setSsoDefaultProfile($authSsoDefaultProfile); |
||
| 165 | |||
| 166 | if ($configData->isAuthBasicEnabled() === false) { |
||
| 167 | $eventMessage->addDescription(__u('Auth Basic enabled')); |
||
| 168 | } |
||
| 169 | } elseif ($authBasicEnabled === false && $configData->isAuthBasicEnabled()) { |
||
| 170 | $configData->setAuthBasicEnabled(false); |
||
| 171 | $configData->setAuthBasicAutoLoginEnabled(false); |
||
| 172 | |||
| 173 | $eventMessage->addDescription(__u('Auth Basic disabled')); |
||
| 174 | } |
||
| 175 | |||
| 176 | return $this->saveConfig( |
||
| 177 | $configData, |
||
| 178 | $this->config, |
||
| 179 | function () use ($eventMessage, $configData) { |
||
| 180 | if ($configData->isMaintenance()) { |
||
| 181 | Util::lockApp($this->session->getUserData()->getId(), 'config'); |
||
| 182 | } |
||
| 183 | |||
| 184 | $this->eventDispatcher->notifyEvent( |
||
| 185 | 'save.config.general', |
||
| 186 | new Event($this, $eventMessage) |
||
| 187 | ); |
||
| 306 | } |