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