GroupMembershipResolver: cosmetics

This commit is contained in:
Thomas Gelf 2018-05-29 23:42:39 +02:00
parent f3056c6f2c
commit c2519b65b5

View File

@ -4,8 +4,8 @@ namespace Icinga\Module\Director\Objects;
use Icinga\Application\Benchmark; use Icinga\Application\Benchmark;
use Icinga\Data\Filter\Filter; use Icinga\Data\Filter\Filter;
use Icinga\Exception\ProgrammingError;
use Icinga\Module\Director\Db; use Icinga\Module\Director\Db;
use LogicException;
use Zend_Db_Select as ZfSelect; use Zend_Db_Select as ZfSelect;
/** /**
@ -52,6 +52,7 @@ abstract class GroupMembershipResolver
/** /**
* @return $this * @return $this
* @throws \Zend_Db_Adapter_Exception
*/ */
public function refreshAllMappings() public function refreshAllMappings()
{ {
@ -61,6 +62,7 @@ abstract class GroupMembershipResolver
/** /**
* @param bool $force * @param bool $force
* @return $this * @return $this
* @throws \Zend_Db_Adapter_Exception
*/ */
public function refreshDb($force = false) public function refreshDb($force = false)
{ {
@ -100,11 +102,11 @@ abstract class GroupMembershipResolver
public function getType() public function getType()
{ {
if ($this->type === null) { if ($this->type === null) {
throw new ProgrammingError( throw new LogicException(sprintf(
'"type" is required when extending %s, got none in %s', '"type" is required when extending %s, got none in %s',
__CLASS__, __CLASS__,
get_class($this) get_class($this)
); ));
} }
return $this->type; return $this->type;
@ -126,16 +128,16 @@ abstract class GroupMembershipResolver
{ {
// Hint: cannot use hasBeenLoadedFromDB, as it is false in onStore() // Hint: cannot use hasBeenLoadedFromDB, as it is false in onStore()
// for new objects // for new objects
if (! $id = $object->get('id')) { if (null === ($id = $object->get('id'))) {
return $this; return $this;
} }
// Disabling for now, how should this work? // Disabling for now, how should this work?
// $this->assertBeenLoadedFromDb($object); // $this->assertBeenLoadedFromDb($object);
if ($this->objects === null) { if ($this->objects === null) {
$this->objects = array(); $this->objects = [];
} }
$this->objects[$object->get('id')] = $object; $this->objects[$id] = $object;
return $this; return $this;
} }
@ -238,6 +240,9 @@ abstract class GroupMembershipResolver
return $this; return $this;
} }
/**
* @throws \Zend_Db_Adapter_Exception
*/
protected function storeNewMappings() protected function storeNewMappings()
{ {
$diff = $this->getDifference($this->newMappings, $this->existingMappings); $diff = $this->getDifference($this->newMappings, $this->existingMappings);
@ -566,7 +571,7 @@ abstract class GroupMembershipResolver
protected function assertBeenLoadedFromDb(IcingaObject $object) protected function assertBeenLoadedFromDb(IcingaObject $object)
{ {
if (! is_int($object->get('id')) && ! ctype_digit($object->get('id'))) { if (! is_int($object->get('id')) && ! ctype_digit($object->get('id'))) {
throw new ProgrammingError( throw new LogicException(
'Group resolver does not support unstored objects' 'Group resolver does not support unstored objects'
); );
} }