Skip to content

Commit

Permalink
Prefer switch rather than if - elseif
Browse files Browse the repository at this point in the history
  • Loading branch information
Al2Klimov committed Jul 24, 2014
1 parent 1902b4f commit af898cc
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions application/controllers/ConfigController.php
Expand Up @@ -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();
Expand Down

0 comments on commit af898cc

Please sign in to comment.