Throw AlreadyExistsException instead of InvalidArgumentException in RoleForm::add()

This commit is contained in:
Eric Lippmann 2015-08-27 13:58:51 +02:00
parent 2e970b2965
commit 1135643fe1
1 changed files with 6 additions and 5 deletions

View File

@ -3,6 +3,7 @@
namespace Icinga\Forms\Security; namespace Icinga\Forms\Security;
use Icinga\Exception\AlreadyExistsException;
use Icinga\Exception\NotFoundError; use Icinga\Exception\NotFoundError;
use InvalidArgumentException; use InvalidArgumentException;
use LogicException; use LogicException;
@ -204,7 +205,7 @@ class RoleForm extends ConfigForm
* @return $this * @return $this
* *
* @throws LogicException If the config is not set * @throws LogicException If the config is not set
* @throws InvalidArgumentException If the role to add already exists * @throws AlreadyExistsException If the role to add already exists
* @see ConfigForm::setConfig() For setting the config. * @see ConfigForm::setConfig() For setting the config.
*/ */
public function add($name, array $values) public function add($name, array $values)
@ -213,10 +214,10 @@ class RoleForm extends ConfigForm
throw new LogicException(sprintf('Can\'t add role \'%s\'. Config is not set', $name)); throw new LogicException(sprintf('Can\'t add role \'%s\'. Config is not set', $name));
} }
if ($this->config->hasSection($name)) { if ($this->config->hasSection($name)) {
throw new InvalidArgumentException(sprintf( throw new AlreadyExistsException(
$this->translate('Can\'t add role \'%s\'. Role already exists'), $this->translate('Can\'t add role \'%s\'. Role already exists'),
$name $name
)); );
} }
$this->config->setSection($name, $values); $this->config->setSection($name, $values);
return $this; return $this;