From af898cc2b3267217e96071192e4b6bef9e7c164a Mon Sep 17 00:00:00 2001 From: Alexander Klimov Date: Thu, 24 Jul 2014 17:35:26 +0200 Subject: [PATCH] Prefer switch rather than if - elseif --- application/controllers/ConfigController.php | 40 +++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index 210a4af68e..a693599a9a 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -233,25 +233,29 @@ public function createauthenticationbackendAction() $backendType = $this->getRequest()->getParam('type'); $authenticationConfig = IcingaConfig::app('authentication')->toArray(); - if ($backendType === 'ldap') { - $form = new LdapBackendForm(); - } else if ($backendType === 'db') { - $form = new DbBackendForm(); - } else if ($backendType === 'autologin') { - $existing = array_filter($authenticationConfig, function ($e) { return $e['backend'] === 'autologin'; }); - if (false === empty($existing)) { - $this->addErrorMessage( - $this->translate('An autologin backend already exists') - ); + switch ($backendType) { + case 'ldap': + $form = new LdapBackendForm(); + break; + case 'db': + $form = new DbBackendForm(); + break; + case 'autologin': + $existing = array_filter($authenticationConfig, function ($e) { return $e['backend'] === 'autologin'; }); + if (false === empty($existing)) { + $this->addErrorMessage( + $this->translate('An autologin backend already exists') + ); + $this->redirectNow('config/configurationerror'); + } + $form = new AutologinBackendForm(); + break; + default: + $this->addErrorMessage(sprintf( + $this->translate('There is no backend type `%s\''), + $backendType + )); $this->redirectNow('config/configurationerror'); - } - $form = new AutologinBackendForm(); - } else { - $this->addErrorMessage(sprintf( - $this->translate('There is no backend type `%s\''), - $backendType - )); - $this->redirectNow('config/configurationerror'); } $request = $this->getRequest();