diff --git a/application/clicommands/SyncruleCommand.php b/application/clicommands/SyncruleCommand.php index 37a3f0e9..876da740 100644 --- a/application/clicommands/SyncruleCommand.php +++ b/application/clicommands/SyncruleCommand.php @@ -167,7 +167,7 @@ class SyncruleCommand extends Command return 'There are pending changes for this Sync Rule. You should' . ' trigger a new Sync Run.'; case 'failing': - return 'This Sync Rule failed: '. $rule->get('last_error_message'); + return 'This Sync Rule failed: ' . $rule->get('last_error_message'); default: throw new RuntimeException('Invalid sync state: ' . $rule->get('sync_state')); } diff --git a/application/controllers/CommandController.php b/application/controllers/CommandController.php index de0ba548..b1838a5c 100644 --- a/application/controllers/CommandController.php +++ b/application/controllers/CommandController.php @@ -90,7 +90,7 @@ class CommandController extends ObjectController $o = $this->object; $this->tabs()->activate('arguments'); $this->addTitle($this->translate('Command arguments: %s'), $o->getObjectName()); - $form = (new IcingaCommandArgumentForm) + $form = (new IcingaCommandArgumentForm()) ->setBranch($this->getBranch()) ->setCommandObject($o); if ($argument = $p->shift('argument')) { diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index 8a5e702d..6b6c089c 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -482,7 +482,7 @@ class ConfigController extends ActionController */ protected function deploymentFailed($checksum, $error = null) { - $extra = $error ? ': ' . $error: ''; + $extra = $error ? ': ' . $error : ''; if ($this->getRequest()->isApiRequest()) { $this->sendJsonError($this->getResponse(), 'Config deployment failed' . $extra); @@ -503,7 +503,8 @@ class ConfigController extends ActionController { $tabs = $this->tabs(); - if ($this->hasPermission(Permission::DEPLOY) + if ( + $this->hasPermission(Permission::DEPLOY) && $deploymentId = $this->params->get('deployment_id') ) { $tabs->add('deployment', [ diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php index 33b5ba5e..5edfbcfa 100644 --- a/application/controllers/HostController.php +++ b/application/controllers/HostController.php @@ -36,7 +36,8 @@ class HostController extends ObjectController $host = $this->getHostObject(); $auth = $this->Auth(); $backend = $this->backend(); - if ($this->isServiceAction() + if ( + $this->isServiceAction() && $backend->canModifyService($host->getObjectName(), $this->getParam('service')) ) { return; @@ -147,7 +148,8 @@ class HostController extends ObjectController if ($info && $auth->hasPermission(Permission::HOSTS)) { $redirectUrl = $info->getUrl(); - } elseif ($info + } elseif ( + $info && (($backend instanceof Monitoring && $auth->hasPermission(Permission::MONITORING_HOSTS)) || ($backend instanceof IcingadbBackend && $auth->hasPermission(Permission::ICINGADB_HOSTS)) ) @@ -593,7 +595,8 @@ class HostController extends ObjectController $host = $this->object; try { $backend = $this->backend(); - if ($host instanceof IcingaHost + if ( + $host instanceof IcingaHost && $host->isObject() && $backend->hasHost($host->getObjectName()) ) { diff --git a/application/controllers/SelfServiceController.php b/application/controllers/SelfServiceController.php index c3c9bb5a..b3f3e23c 100644 --- a/application/controllers/SelfServiceController.php +++ b/application/controllers/SelfServiceController.php @@ -397,7 +397,7 @@ class SelfServiceController extends ActionController $params['parent_zone'] = $zoneName; $params['ca_server'] = $master->getObjectName(); $params['parent_endpoints'] = $endpointNames; - $params['accept_config'] = $host->getSingleResolvedProperty('accept_config')=== 'y'; + $params['accept_config'] = $host->getSingleResolvedProperty('accept_config') === 'y'; } protected function addStringSettingsToParams(Settings $settings, array $keys, array &$params) diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index b62f317e..c0a6182c 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -29,7 +29,8 @@ class ServiceController extends ObjectController protected function checkDirectorPermissions() { - if ($this->host + if ( + $this->host && $this->object && $this->backend()->canModifyService($this->host->getObjectName(), $this->object->getObjectName()) ) { @@ -190,7 +191,8 @@ class ServiceController extends ObjectController } try { - if ($object->isTemplate() + if ( + $object->isTemplate() && $object->getResolvedProperty('check_command_id') ) { $this->view->actionLinks .= ' ' . $this->view->qlink( diff --git a/application/controllers/SuggestController.php b/application/controllers/SuggestController.php index 659c48c9..40076e66 100644 --- a/application/controllers/SuggestController.php +++ b/application/controllers/SuggestController.php @@ -122,7 +122,7 @@ class SuggestController extends ActionController protected function suggestServicenames() { - $r=array(); + $r = array(); $this->assertPermission('director/services'); $db = $this->db()->getDbAdapter(); $for_host = $this->getRequest()->getPost('for_host'); @@ -152,7 +152,7 @@ class SuggestController extends ActionController $matcher = HostApplyMatches::prepare($tmp_host); foreach ($this->getAllApplyRules() as $rule) { if ($matcher->matchesFilter($rule->filter)) { //TODO - $r[]=$rule->name; + $r[] = $rule->name; } } } @@ -291,7 +291,7 @@ class SuggestController extends ActionController $db = $this->db()->getDbAdapter(); $query = $db->select() - ->from(['f' =>'director_datafield'], []) + ->from(['f' => 'director_datafield'], []) ->join( ['sid' => 'director_datafield_setting'], 'sid.datafield_id = f.id AND sid.setting_name = \'datalist_id\'', @@ -369,7 +369,7 @@ class SuggestController extends ActionController protected function getAllApplyRules() { - $allApplyRules=$this->fetchAllApplyRules(); + $allApplyRules = $this->fetchAllApplyRules(); foreach ($allApplyRules as $rule) { $rule->filter = Filter::fromQueryString($rule->assign_filter); } diff --git a/application/forms/BasketUploadForm.php b/application/forms/BasketUploadForm.php index aa262588..c922b784 100644 --- a/application/forms/BasketUploadForm.php +++ b/application/forms/BasketUploadForm.php @@ -65,7 +65,8 @@ class BasketUploadForm extends DirectorObjectForm throw new IcingaException('Got no file'); } - if (! isset($_FILES['uploaded_file']['tmp_name']) + if ( + ! isset($_FILES['uploaded_file']['tmp_name']) || ! is_uploaded_file($_FILES['uploaded_file']['tmp_name']) ) { $this->addError('Got no uploaded file'); diff --git a/application/forms/DeployFormsBug7530.php b/application/forms/DeployFormsBug7530.php index 4d456ae1..b31d3563 100644 --- a/application/forms/DeployFormsBug7530.php +++ b/application/forms/DeployFormsBug7530.php @@ -51,11 +51,13 @@ trait DeployFormsBug7530 ]; foreach ($objectTypes as $objectType) { - if ((int) $db->fetchOne( - $db->select() + if ( + (int) $db->fetchOne( + $db->select() ->from($objectType, 'COUNT(*)') ->where('zone_id IN (?)', $zoneIds) - ) > 0) { + ) > 0 + ) { return true; } } @@ -70,7 +72,8 @@ trait DeployFormsBug7530 $version = $this->api->getVersion(); if ($version === null) { throw new \RuntimeException($this->translate('Unable to detect your Icinga 2 Core version')); - } elseif (\version_compare($version, '2.11.0', '>=') + } elseif ( + \version_compare($version, '2.11.0', '>=') && \version_compare($version, '2.12.0', '<') ) { return true; diff --git a/application/forms/DeploymentLinkForm.php b/application/forms/DeploymentLinkForm.php index f5cd3689..b5d9b033 100644 --- a/application/forms/DeploymentLinkForm.php +++ b/application/forms/DeploymentLinkForm.php @@ -157,7 +157,7 @@ class DeploymentLinkForm extends DirectorForm protected function deploymentFailed($checksum, $error = null) { - $extra = $error ? ': ' . $error: ''; + $extra = $error ? ': ' . $error : ''; if ($this->getRequest()->isApiRequest()) { throw new IcingaException('Not yet'); diff --git a/application/forms/DirectorDatafieldForm.php b/application/forms/DirectorDatafieldForm.php index ab0dcd8a..3cb7885a 100644 --- a/application/forms/DirectorDatafieldForm.php +++ b/application/forms/DirectorDatafieldForm.php @@ -175,7 +175,7 @@ class DirectorDatafieldForm extends DirectorObjectForm $error = $e->getMessage(); $types = $this->optionalEnum(array()); } - + $this->addElement('select', 'datatype', array( 'label' => $this->translate('Data type'), 'description' => $this->translate('Field type'), diff --git a/application/forms/IcingaCloneObjectForm.php b/application/forms/IcingaCloneObjectForm.php index 8381eee7..a5c8f2b3 100644 --- a/application/forms/IcingaCloneObjectForm.php +++ b/application/forms/IcingaCloneObjectForm.php @@ -54,7 +54,8 @@ class IcingaCloneObjectForm extends DirectorForm )); } - if (!$branchOnly && ($this->object instanceof IcingaHost + if ( + !$branchOnly && ($this->object instanceof IcingaHost || $this->object instanceof IcingaServiceSet) ) { $this->addBoolean('clone_services', [ @@ -97,7 +98,8 @@ class IcingaCloneObjectForm extends DirectorForm } } - if (($this->object->isTemplate() || $this->object instanceof IcingaCommand) + if ( + ($this->object->isTemplate() || $this->object instanceof IcingaCommand) && $this->object->supportsFields() ) { $this->addBoolean('clone_fields', [ diff --git a/application/forms/IcingaHostForm.php b/application/forms/IcingaHostForm.php index ed572515..d7bca9c3 100644 --- a/application/forms/IcingaHostForm.php +++ b/application/forms/IcingaHostForm.php @@ -209,7 +209,8 @@ class IcingaHostForm extends DirectorObjectForm */ protected function addGroupsElement() { - if ($this->hasHostGroupRestriction() + if ( + $this->hasHostGroupRestriction() && ! $this->getAuth()->hasPermission(Permission::GROUPS_FOR_RESTRICTED_HOSTS) ) { return $this; diff --git a/application/forms/IcingaServiceForm.php b/application/forms/IcingaServiceForm.php index 5744d8d3..3e21bc8c 100644 --- a/application/forms/IcingaServiceForm.php +++ b/application/forms/IcingaServiceForm.php @@ -282,10 +282,12 @@ class IcingaServiceForm extends DirectorObjectForm $db = $this->db->getDbAdapter(); $host->unsetOverriddenServiceVars($this->object->getObjectName())->store(); - if ($db->insert('icinga_host_service_blacklist', [ + if ( + $db->insert('icinga_host_service_blacklist', [ 'host_id' => $host->get('id'), 'service_id' => $service->get('id') - ])) { + ]) + ) { $msg = sprintf( $this->translate('%s has been deactivated on %s'), $service->getObjectName(), diff --git a/application/forms/KickstartForm.php b/application/forms/KickstartForm.php index 0079cfbc..0c44fbdd 100644 --- a/application/forms/KickstartForm.php +++ b/application/forms/KickstartForm.php @@ -41,8 +41,10 @@ class KickstartForm extends DirectorForm $this->addResourceConfigElements(); $this->addResourceDisplayGroup(); - if (!$this->config()->get('db', 'resource') - || ($this->config()->get('db', 'resource') !== $this->getResourceName())) { + if ( + !$this->config()->get('db', 'resource') + || ($this->config()->get('db', 'resource') !== $this->getResourceName()) + ) { return; } } @@ -353,8 +355,10 @@ class KickstartForm extends DirectorForm } } - if ($this->getSubmitLabel() === $this->createDbLabel - || $this->getSubmitLabel() === $this->migrateDbLabel) { + if ( + $this->getSubmitLabel() === $this->createDbLabel + || $this->getSubmitLabel() === $this->migrateDbLabel + ) { $this->migrations()->applyPendingMigrations(); parent::onSuccess(); } @@ -448,7 +452,8 @@ class KickstartForm extends DirectorForm { if ($resourceName = $this->getResourceName()) { $resourceConfig = ResourceFactory::getResourceConfig($resourceName); - if (!isset($resourceConfig->charset) + if ( + !isset($resourceConfig->charset) || !in_array($resourceConfig->charset, array('utf8', 'utf8mb4', 'UTF8', 'UTF-8')) ) { if ($resource = $this->getElement('resource')) { diff --git a/application/views/helpers/RenderPlainObject.php b/application/views/helpers/RenderPlainObject.php index 84866115..5e66173f 100644 --- a/application/views/helpers/RenderPlainObject.php +++ b/application/views/helpers/RenderPlainObject.php @@ -1,4 +1,5 @@ getVersion(); - if ($version === null || + if ( + $version === null || ((version_compare($version, '2.8.2', '>=') && version_compare($version, '2.10.2', '<'))) ) { $this->client->disconnect(); @@ -681,7 +682,8 @@ constants continue; } - if (in_array('startup.log', $availableFiles) + if ( + in_array('startup.log', $availableFiles) && in_array('status', $availableFiles) ) { if ($this->getStagedFile($stage, 'status') === '0') { diff --git a/library/Director/Core/LegacyDeploymentApi.php b/library/Director/Core/LegacyDeploymentApi.php index 0ab77e03..d6b5b7ca 100644 --- a/library/Director/Core/LegacyDeploymentApi.php +++ b/library/Director/Core/LegacyDeploymentApi.php @@ -55,7 +55,8 @@ class LegacyDeploymentApi implements DeploymentApiInterface continue; } - if (in_array('startup.log', $availableFiles) + if ( + in_array('startup.log', $availableFiles) && in_array('status', $availableFiles) ) { $status = $this->getStagedFile($stage, 'status'); @@ -91,7 +92,8 @@ class LegacyDeploymentApi implements DeploymentApiInterface // try to expire old deployments foreach ($uncollected as $name => $deployment) { /** @var DirectorDeploymentLog $deployment */ - if ($deployment->get('dump_succeeded') === 'n' + if ( + $deployment->get('dump_succeeded') === 'n' || $deployment->get('startup_succeeded') === null ) { $start_time = strtotime($deployment->start_time); @@ -106,7 +108,8 @@ class LegacyDeploymentApi implements DeploymentApiInterface } foreach ($this->listPackageStages($packageName) as $stage) { - if (array_key_exists($stage, $uncollected) + if ( + array_key_exists($stage, $uncollected) && $uncollected[$stage]->get('startup_succeeded') === null ) { continue; @@ -177,7 +180,8 @@ class LegacyDeploymentApi implements DeploymentApiInterface while ($file = readdir($dh)) { if ($file === '.' || $file === '..') { continue; - } elseif (is_dir($this->deploymentPath . DIRECTORY_SEPARATOR . $file) + } elseif ( + is_dir($this->deploymentPath . DIRECTORY_SEPARATOR . $file) && substr($file, 0, 9) === 'director-' ) { $stages[] = $file; @@ -234,7 +238,7 @@ class LegacyDeploymentApi implements DeploymentApiInterface // 'module_name' => $moduleName, )); - $stage_name = 'director-' .date('Ymd-His'); + $stage_name = 'director-' . date('Ymd-His'); $deployment->set('stage_name', $stage_name); try { diff --git a/library/Director/Core/RestApiResponse.php b/library/Director/Core/RestApiResponse.php index 43516f7e..5f607205 100644 --- a/library/Director/Core/RestApiResponse.php +++ b/library/Director/Core/RestApiResponse.php @@ -17,13 +17,13 @@ class RestApiResponse public static function fromJsonResult($json) { - $response = new static; + $response = new static(); return $response->parseJsonResult($json); } public static function fromErrorMessage($error) { - $response = new static; + $response = new static(); $response->errorMessage = $error; return $response; diff --git a/library/Director/CustomVariable/CustomVariables.php b/library/Director/CustomVariable/CustomVariables.php index 01227c59..bb0b44b3 100644 --- a/library/Director/CustomVariable/CustomVariables.php +++ b/library/Director/CustomVariable/CustomVariables.php @@ -183,7 +183,7 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer ) )->where(sprintf('v.%s = ?', $object->getVarsIdColumn()), $object->get('id')); - $vars = new CustomVariables; + $vars = new CustomVariables(); foreach ($db->fetchAll($query) as $row) { $vars->vars[$row->varname] = CustomVariable::fromDbRow($row); } @@ -194,7 +194,7 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer public static function forStoredRows($rows) { - $vars = new CustomVariables; + $vars = new CustomVariables(); foreach ($rows as $row) { $vars->vars[$row->varname] = CustomVariable::fromDbRow($row); } @@ -383,7 +383,7 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer } if ($out !== '') { - $out = "\n".$out; + $out = "\n" . $out; } return $out; diff --git a/library/Director/Daemon/DaemonDb.php b/library/Director/Daemon/DaemonDb.php index 7772b3a4..7ba3d21a 100644 --- a/library/Director/Daemon/DaemonDb.php +++ b/library/Director/Daemon/DaemonDb.php @@ -13,6 +13,7 @@ use React\EventLoop\LoopInterface; use React\Promise\Deferred; use RuntimeException; use SplObjectStorage; + use function React\Promise\reject; use function React\Promise\resolve; diff --git a/library/Director/Daemon/DeploymentChecker.php b/library/Director/Daemon/DeploymentChecker.php index 82d6d058..853bd927 100644 --- a/library/Director/Daemon/DeploymentChecker.php +++ b/library/Director/Daemon/DeploymentChecker.php @@ -6,6 +6,7 @@ use Exception; use Icinga\Module\Director\Db; use Icinga\Module\Director\Objects\DirectorDeploymentLog; use React\EventLoop\LoopInterface; + use function React\Promise\resolve; class DeploymentChecker implements DbBasedComponent diff --git a/library/Director/Daemon/JobRunner.php b/library/Director/Daemon/JobRunner.php index 78d77475..e50f931e 100644 --- a/library/Director/Daemon/JobRunner.php +++ b/library/Director/Daemon/JobRunner.php @@ -10,6 +10,7 @@ use Icinga\Module\Director\Objects\DirectorJob; use React\ChildProcess\Process; use React\EventLoop\LoopInterface; use React\Promise\Promise; + use function React\Promise\resolve; class JobRunner implements DbBasedComponent @@ -139,9 +140,11 @@ class JobRunner implements DbBasedComponent { $db = $this->db->getDbAdapter(); - foreach ($db->fetchCol( - $db->select()->from('director_job', 'id')->where('disabled = ?', 'n') - ) as $id) { + foreach ( + $db->fetchCol( + $db->select()->from('director_job', 'id')->where('disabled = ?', 'n') + ) as $id + ) { $this->scheduledIds[] = (int) $id; }; } diff --git a/library/Director/Daemon/LogProxy.php b/library/Director/Daemon/LogProxy.php index 0b58ae8b..40643bea 100644 --- a/library/Director/Daemon/LogProxy.php +++ b/library/Director/Daemon/LogProxy.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Daemon; use Exception; use Icinga\Module\Director\Db; + use function React\Promise\resolve; class LogProxy implements DbBasedComponent diff --git a/library/Director/Daemon/ProcessList.php b/library/Director/Daemon/ProcessList.php index 85b9aac9..6f9c4eb1 100644 --- a/library/Director/Daemon/ProcessList.php +++ b/library/Director/Daemon/ProcessList.php @@ -8,6 +8,7 @@ use ipl\Stdlib\EventEmitter; use React\ChildProcess\Process; use React\EventLoop\LoopInterface; use React\Promise\Deferred; + use function React\Promise\resolve; class ProcessList diff --git a/library/Director/Data/DataArrayHelper.php b/library/Director/Data/DataArrayHelper.php index 442eb0fd..605724c1 100644 --- a/library/Director/Data/DataArrayHelper.php +++ b/library/Director/Data/DataArrayHelper.php @@ -3,6 +3,7 @@ namespace Icinga\Module\Director\Data; use InvalidArgumentException; + use function array_diff; use function array_key_exists; use function implode; diff --git a/library/Director/Data/Db/DbObject.php b/library/Director/Data/Db/DbObject.php index 114b61b9..74f6799d 100644 --- a/library/Director/Data/Db/DbObject.php +++ b/library/Director/Data/Db/DbObject.php @@ -103,7 +103,8 @@ abstract class DbObject */ protected function __construct() { - if ($this->table === null + if ( + $this->table === null || $this->keyName === null || $this->defaultProperties === null ) { @@ -366,7 +367,8 @@ abstract class DbObject )); } - if ((is_numeric($value) || is_string($value)) + if ( + (is_numeric($value) || is_string($value)) && (string) $value === (string) $this->get($key) ) { return $this; @@ -385,7 +387,8 @@ abstract class DbObject return $this; } if ($key === 'id' || substr($key, -3) === '_id') { - if ($value !== null + if ( + $value !== null && $this->properties[$key] !== null && (int) $value === (int) $this->properties[$key] ) { @@ -1206,7 +1209,8 @@ abstract class DbObject { $class = get_called_class(); if (static::hasPrefetched($key)) { - if (is_string($key) + if ( + is_string($key) && array_key_exists($class, self::$prefetchedNames) && array_key_exists($key, self::$prefetchedNames[$class]) ) { @@ -1239,7 +1243,8 @@ abstract class DbObject } if (array_key_exists($class, self::$prefetched)) { - if (is_string($key) + if ( + is_string($key) && array_key_exists($class, self::$prefetchedNames) && array_key_exists($key, self::$prefetchedNames[$class]) ) { @@ -1283,7 +1288,7 @@ abstract class DbObject return $prefetched; } - $obj = new static; + $obj = new static(); if (self::$dbObjectStore !== null && $obj->hasUuidColumn()) { $table = $obj->getTableName(); assert($connection instanceof Db); @@ -1311,7 +1316,7 @@ abstract class DbObject return $prefetched; } /** @var DbObject $obj */ - $obj = new static; + $obj = new static(); if (self::$dbObjectStore !== null && $obj->hasUuidColumn()) { $table = $obj->getTableName(); @@ -1373,7 +1378,7 @@ abstract class DbObject $db = $connection->getDbAdapter(); if ($query === null) { - $dummy = new static; + $dummy = new static(); $select = $db->select()->from($dummy->table); } else { $select = $query; @@ -1382,7 +1387,7 @@ abstract class DbObject foreach ($rows as $row) { /** @var DbObject $obj */ - $obj = new static; + $obj = new static(); $obj->setConnection($connection)->setDbProperties($row); if ($keyColumn === null) { $objects[] = $obj; @@ -1452,7 +1457,7 @@ abstract class DbObject } /** @var DbObject $obj */ - $obj = new static; + $obj = new static(); if (self::$dbObjectStore !== null && $obj->hasUuidColumn()) { $table = $obj->getTableName(); assert($connection instanceof Db); @@ -1471,7 +1476,7 @@ abstract class DbObject public static function uniqueIdExists(UuidInterface $uuid, DbConnection $connection) { $db = $connection->getDbAdapter(); - $obj = new static; + $obj = new static(); $column = $obj->getUuidColumn(); $query = $db->select() ->from($obj->getTableName(), $column) @@ -1490,7 +1495,7 @@ abstract class DbObject throw new NotFoundError(sprintf( 'No %s with UUID=%s has been found', - (new static)->getTableName(), + (new static())->getTableName(), $uuid->toString() )); } @@ -1498,7 +1503,7 @@ abstract class DbObject public static function loadWithUniqueId(UuidInterface $uuid, DbConnection $connection): ?DbObject { $db = $connection->getDbAdapter(); - $obj = new static; + $obj = new static(); if (self::$dbObjectStore !== null && $obj->hasUuidColumn()) { $table = $obj->getTableName(); diff --git a/library/Director/Data/Db/ServiceSetQueryBuilder.php b/library/Director/Data/Db/ServiceSetQueryBuilder.php index 597fe0e6..1c7e288e 100644 --- a/library/Director/Data/Db/ServiceSetQueryBuilder.php +++ b/library/Director/Data/Db/ServiceSetQueryBuilder.php @@ -67,7 +67,7 @@ class ServiceSetQueryBuilder { return $this->db ->select() - ->from(['o' =>self::TABLE], []) + ->from(['o' => self::TABLE], []) ->joinLeft(['os' => self::SET_TABLE], 'os.id = o.service_set_id', []) ->where('os.uuid = ?', $this->connection->quoteBinary($set->getUniqueId()->getBytes())); } diff --git a/library/Director/Data/Json.php b/library/Director/Data/Json.php index 78b3e674..d882dd71 100644 --- a/library/Director/Data/Json.php +++ b/library/Director/Data/Json.php @@ -3,6 +3,7 @@ namespace Icinga\Module\Director\Data; use Icinga\Module\Director\Exception\JsonEncodeException; + use function json_decode; use function json_encode; use function json_last_error; diff --git a/library/Director/Data/ObjectImporter.php b/library/Director/Data/ObjectImporter.php index 231ad1c4..3bf89f04 100644 --- a/library/Director/Data/ObjectImporter.php +++ b/library/Director/Data/ObjectImporter.php @@ -120,7 +120,8 @@ class ObjectImporter */ protected function loadExistingObject(string $implementation, stdClass $plain): ?DbObject { - if (isset($plain->uuid) + if ( + isset($plain->uuid) && $instance = $implementation::loadWithUniqueId(Uuid::fromString($plain->uuid), $this->db) ) { return $instance; diff --git a/library/Director/Data/SerializableValue.php b/library/Director/Data/SerializableValue.php index 57842245..ed06b80a 100644 --- a/library/Director/Data/SerializableValue.php +++ b/library/Director/Data/SerializableValue.php @@ -5,6 +5,7 @@ namespace Icinga\Module\Director\Data; use InvalidArgumentException; use JsonSerializable; use stdClass; + use function get_class; use function gettype; use function is_array; @@ -21,7 +22,7 @@ class SerializableValue implements Serializable */ public static function fromSerialization($value) { - $self = new static; + $self = new static(); static::assertSerializableValue($value); $self->value = $value; diff --git a/library/Director/DataType/DataTypeBoolean.php b/library/Director/DataType/DataTypeBoolean.php index d9edc602..1ae45c18 100644 --- a/library/Director/DataType/DataTypeBoolean.php +++ b/library/Director/DataType/DataTypeBoolean.php @@ -21,7 +21,7 @@ class DataTypeBoolean extends DataTypeHook $vhClass = 'Zend_Form_Decorator_ViewHelper'; $decorators = $element->getDecorators(); if (array_key_exists($vhClass, $decorators)) { - $decorators[$vhClass] = new ViewHelperRaw; + $decorators[$vhClass] = new ViewHelperRaw(); $element->setDecorators($decorators); } diff --git a/library/Director/DataType/DataTypeDatalist.php b/library/Director/DataType/DataTypeDatalist.php index 354c7c37..f1030585 100644 --- a/library/Director/DataType/DataTypeDatalist.php +++ b/library/Director/DataType/DataTypeDatalist.php @@ -76,10 +76,12 @@ class DataTypeDatalist extends DataTypeHook */ protected function createEntryIfNotExists(Db $db, $listId, $entry) { - if (! DirectorDatalistEntry::exists([ + if ( + ! DirectorDatalistEntry::exists([ 'list_id' => $listId, 'entry_name' => $entry, - ], $db)) { + ], $db) + ) { DirectorDatalistEntry::create([ 'list_id' => $listId, 'entry_name' => $entry, diff --git a/library/Director/DataType/DataTypeNumber.php b/library/Director/DataType/DataTypeNumber.php index cd47f88b..b6a1ee04 100644 --- a/library/Director/DataType/DataTypeNumber.php +++ b/library/Director/DataType/DataTypeNumber.php @@ -12,7 +12,7 @@ class DataTypeNumber extends DataTypeHook { $element = $form->createElement('text', $name) ->addValidator('int') - ->addFilter(new FilterInt); + ->addFilter(new FilterInt()); return $element; } diff --git a/library/Director/Db.php b/library/Director/Db.php index 2a8d6c0c..1cb625e9 100644 --- a/library/Director/Db.php +++ b/library/Director/Db.php @@ -528,7 +528,7 @@ class Db extends DbConnection { $filters = array( 'methods_execute IN (?)' => array('PluginCheck', 'IcingaCheck'), - + ); return $this->enumIcingaObjects('command', $filters); } diff --git a/library/Director/Db/Branch/Branch.php b/library/Director/Db/Branch/Branch.php index c99b1bdd..49a5021c 100644 --- a/library/Director/Db/Branch/Branch.php +++ b/library/Director/Db/Branch/Branch.php @@ -40,7 +40,7 @@ class Branch public static function fromDbRow(stdClass $row) { - $self = new static; + $self = new static(); if (is_resource($row->uuid)) { $row->uuid = stream_get_contents($row->uuid); } @@ -85,7 +85,7 @@ class Branch return $hook->getBranchForRequest($request, $store, $auth); } - return new Branch; + return new Branch(); } /** diff --git a/library/Director/Db/Branch/BranchActivity.php b/library/Director/Db/Branch/BranchActivity.php index e95ac7d9..c877273e 100644 --- a/library/Director/Db/Branch/BranchActivity.php +++ b/library/Director/Db/Branch/BranchActivity.php @@ -49,8 +49,8 @@ class BranchActivity protected $formerProperties; public function __construct( - UuidInterface $objectUuid, - UuidInterface $branchUuid, + UuidInterface $objectUuid, + UuidInterface $branchUuid, $action, $objectType, $author, diff --git a/library/Director/Db/Branch/BranchSettings.php b/library/Director/Db/Branch/BranchSettings.php index b3fd1645..6b157c54 100644 --- a/library/Director/Db/Branch/BranchSettings.php +++ b/library/Director/Db/Branch/BranchSettings.php @@ -3,6 +3,7 @@ namespace Icinga\Module\Director\Db\Branch; use Icinga\Module\Director\Data\Json; + use function in_array; /** diff --git a/library/Director/Db/Branch/BranchSupport.php b/library/Director/Db/Branch/BranchSupport.php index 74be0212..c0494ae9 100644 --- a/library/Director/Db/Branch/BranchSupport.php +++ b/library/Director/Db/Branch/BranchSupport.php @@ -25,21 +25,21 @@ class BranchSupport const TABLE_ICINGA_USERGROUP = 'icinga_usergroup'; const TABLE_ICINGA_ZONE = 'icinga_zone'; - const BRANCHED_TABLE_ICINGA_APIUSER = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_APIUSER; - const BRANCHED_TABLE_ICINGA_COMMAND = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_COMMAND; - const BRANCHED_TABLE_ICINGA_DEPENDENCY = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_DEPENDENCY; - const BRANCHED_TABLE_ICINGA_ENDPOINT = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_ENDPOINT; - const BRANCHED_TABLE_ICINGA_HOST = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_HOST; - const BRANCHED_TABLE_ICINGA_HOSTGROUP = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_HOSTGROUP; - const BRANCHED_TABLE_ICINGA_NOTIFICATION = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_NOTIFICATION; - const BRANCHED_TABLE_ICINGA_SCHEDULED_DOWNTIME = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_SCHEDULED_DOWNTIME; - const BRANCHED_TABLE_ICINGA_SERVICE = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_SERVICE; - const BRANCHED_TABLE_ICINGA_SERVICEGROUP = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_SERVICEGROUP; - const BRANCHED_TABLE_ICINGA_SERVICE_SET = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_SERVICE_SET; - const BRANCHED_TABLE_ICINGA_TIMEPERIOD = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_TIMEPERIOD; - const BRANCHED_TABLE_ICINGA_USER = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_USER; - const BRANCHED_TABLE_ICINGA_USERGROUP = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_USERGROUP; - const BRANCHED_TABLE_ICINGA_ZONE = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_ZONE; + const BRANCHED_TABLE_ICINGA_APIUSER = self::BRANCHED_TABLE_PREFIX . self::TABLE_ICINGA_APIUSER; + const BRANCHED_TABLE_ICINGA_COMMAND = self::BRANCHED_TABLE_PREFIX . self::TABLE_ICINGA_COMMAND; + const BRANCHED_TABLE_ICINGA_DEPENDENCY = self::BRANCHED_TABLE_PREFIX . self::TABLE_ICINGA_DEPENDENCY; + const BRANCHED_TABLE_ICINGA_ENDPOINT = self::BRANCHED_TABLE_PREFIX . self::TABLE_ICINGA_ENDPOINT; + const BRANCHED_TABLE_ICINGA_HOST = self::BRANCHED_TABLE_PREFIX . self::TABLE_ICINGA_HOST; + const BRANCHED_TABLE_ICINGA_HOSTGROUP = self::BRANCHED_TABLE_PREFIX . self::TABLE_ICINGA_HOSTGROUP; + const BRANCHED_TABLE_ICINGA_NOTIFICATION = self::BRANCHED_TABLE_PREFIX . self::TABLE_ICINGA_NOTIFICATION; + const BRANCHED_TABLE_ICINGA_SCHEDULED_DOWNTIME = self::BRANCHED_TABLE_PREFIX . self::TABLE_ICINGA_SCHEDULED_DOWNTIME; + const BRANCHED_TABLE_ICINGA_SERVICE = self::BRANCHED_TABLE_PREFIX . self::TABLE_ICINGA_SERVICE; + const BRANCHED_TABLE_ICINGA_SERVICEGROUP = self::BRANCHED_TABLE_PREFIX . self::TABLE_ICINGA_SERVICEGROUP; + const BRANCHED_TABLE_ICINGA_SERVICE_SET = self::BRANCHED_TABLE_PREFIX . self::TABLE_ICINGA_SERVICE_SET; + const BRANCHED_TABLE_ICINGA_TIMEPERIOD = self::BRANCHED_TABLE_PREFIX . self::TABLE_ICINGA_TIMEPERIOD; + const BRANCHED_TABLE_ICINGA_USER = self::BRANCHED_TABLE_PREFIX . self::TABLE_ICINGA_USER; + const BRANCHED_TABLE_ICINGA_USERGROUP = self::BRANCHED_TABLE_PREFIX . self::TABLE_ICINGA_USERGROUP; + const BRANCHED_TABLE_ICINGA_ZONE = self::BRANCHED_TABLE_PREFIX . self::TABLE_ICINGA_ZONE; const OBJECT_TABLES = [ self::TABLE_ICINGA_APIUSER, diff --git a/library/Director/Db/Branch/UuidLookup.php b/library/Director/Db/Branch/UuidLookup.php index 4db7866b..a728c1c7 100644 --- a/library/Director/Db/Branch/UuidLookup.php +++ b/library/Director/Db/Branch/UuidLookup.php @@ -8,6 +8,7 @@ use Icinga\Module\Director\Objects\IcingaHost; use Icinga\Module\Director\Objects\IcingaServiceSet; use Ramsey\Uuid\Uuid; use Ramsey\Uuid\UuidInterface; + use function is_int; use function is_resource; use function is_string; diff --git a/library/Director/Db/DbUtil.php b/library/Director/Db/DbUtil.php index f98e213e..1dacbef0 100644 --- a/library/Director/Db/DbUtil.php +++ b/library/Director/Db/DbUtil.php @@ -8,6 +8,7 @@ use gipfl\ZfDb\Expr; use Zend_Db_Adapter_Abstract; use Zend_Db_Adapter_Pdo_Pgsql; use Zend_Db_Expr; + use function bin2hex; use function is_array; use function is_resource; diff --git a/library/Director/Db/IcingaObjectFilterHelper.php b/library/Director/Db/IcingaObjectFilterHelper.php index 2d9f8f37..07320e1a 100644 --- a/library/Director/Db/IcingaObjectFilterHelper.php +++ b/library/Director/Db/IcingaObjectFilterHelper.php @@ -59,7 +59,8 @@ class IcingaObjectFilterHelper if ($branchuuid) { if ($inheritanceType === self::INHERIT_DIRECT) { return $query->where('imports LIKE \'%"' . $template->getObjectName() . '"%\''); - } elseif ($inheritanceType === self::INHERIT_INDIRECT + } elseif ( + $inheritanceType === self::INHERIT_INDIRECT || $inheritanceType === self::INHERIT_DIRECT_OR_INDIRECT ) { $tree = new TemplateTree($type, $template->getConnection()); @@ -90,7 +91,8 @@ class IcingaObjectFilterHelper if ($inheritanceType === self::INHERIT_DIRECT) { $sub->where("$i.parent_{$type}_id = ?", $id); - } elseif ($inheritanceType === self::INHERIT_INDIRECT + } elseif ( + $inheritanceType === self::INHERIT_INDIRECT || $inheritanceType === self::INHERIT_DIRECT_OR_INDIRECT ) { $tree = new TemplateTree($type, $template->getConnection()); diff --git a/library/Director/DirectorObject/Automation/BasketSnapshot.php b/library/Director/DirectorObject/Automation/BasketSnapshot.php index 9638e492..26639798 100644 --- a/library/Director/DirectorObject/Automation/BasketSnapshot.php +++ b/library/Director/DirectorObject/Automation/BasketSnapshot.php @@ -443,7 +443,8 @@ class BasketSnapshot extends DbObject foreach ($filter as $column => $value) { $select->where("$column = ?", $value); } - } elseif (! $dummy->isGroup() + } elseif ( + ! $dummy->isGroup() // TODO: this is ugly. && ! $dummy instanceof IcingaDependency && ! $dummy instanceof IcingaTimePeriod diff --git a/library/Director/DirectorObject/Automation/BasketSnapshotFieldResolver.php b/library/Director/DirectorObject/Automation/BasketSnapshotFieldResolver.php index e565f77b..5a9e4d69 100644 --- a/library/Director/DirectorObject/Automation/BasketSnapshotFieldResolver.php +++ b/library/Director/DirectorObject/Automation/BasketSnapshotFieldResolver.php @@ -87,9 +87,11 @@ class BasketSnapshotFieldResolver $db = $this->targetDb->getDbAdapter(); - foreach ($db->fetchAll( - $db->select()->from($table)->where("$objectKey = ?", $objectId) - ) as $mapping) { + foreach ( + $db->fetchAll( + $db->select()->from($table)->where("$objectKey = ?", $objectId) + ) as $mapping + ) { $existingFields[(int) $mapping->datafield_id] = $mapping; } foreach ($object->fields as $field) { diff --git a/library/Director/DirectorObject/Automation/CompareBasketObject.php b/library/Director/DirectorObject/Automation/CompareBasketObject.php index f1ab6a91..76844ff2 100644 --- a/library/Director/DirectorObject/Automation/CompareBasketObject.php +++ b/library/Director/DirectorObject/Automation/CompareBasketObject.php @@ -5,6 +5,7 @@ namespace Icinga\Module\Director\DirectorObject\Automation; use Icinga\Module\Director\Core\Json; use ipl\Html\Error; use RuntimeException; + use function array_key_exists; use function is_array; use function is_object; diff --git a/library/Director/DirectorObject/Lookup/AppliedServiceInfo.php b/library/Director/DirectorObject/Lookup/AppliedServiceInfo.php index abda497e..f810335b 100644 --- a/library/Director/DirectorObject/Lookup/AppliedServiceInfo.php +++ b/library/Director/DirectorObject/Lookup/AppliedServiceInfo.php @@ -31,7 +31,7 @@ class AppliedServiceInfo implements ServiceInfo public function __construct($hostName, $serviceName, $serviceApplyRuleId, UuidInterface $uuid) { $this->hostName = $hostName; - $this->serviceName= $serviceName; + $this->serviceName = $serviceName; $this->serviceApplyRuleId = $serviceApplyRuleId; $this->uuid = $uuid; } diff --git a/library/Director/DirectorObject/Lookup/InheritedServiceInfo.php b/library/Director/DirectorObject/Lookup/InheritedServiceInfo.php index 875d5fb7..bea8ae0f 100644 --- a/library/Director/DirectorObject/Lookup/InheritedServiceInfo.php +++ b/library/Director/DirectorObject/Lookup/InheritedServiceInfo.php @@ -30,7 +30,7 @@ class InheritedServiceInfo implements ServiceInfo { $this->hostName = $hostName; $this->hostTemplateName = $hostTemplateName; - $this->serviceName= $serviceName; + $this->serviceName = $serviceName; $this->uuid = $uuid; } diff --git a/library/Director/DirectorObject/Lookup/ServiceFinder.php b/library/Director/DirectorObject/Lookup/ServiceFinder.php index a14d8538..8c4feb20 100644 --- a/library/Director/DirectorObject/Lookup/ServiceFinder.php +++ b/library/Director/DirectorObject/Lookup/ServiceFinder.php @@ -36,13 +36,15 @@ class ServiceFinder public static function find(IcingaHost $host, $serviceName) { - foreach ([ + foreach ( + [ SingleServiceInfo::class, InheritedServiceInfo::class, ServiceSetServiceInfo::class, AppliedServiceInfo::class, AppliedServiceSetServiceInfo::class, - ] as $class) { + ] as $class + ) { /** @var ServiceInfo $class */ if ($info = $class::find($host, $serviceName)) { return $info; diff --git a/library/Director/Field/FieldSpec.php b/library/Director/Field/FieldSpec.php index 29baa0bc..3a138271 100644 --- a/library/Director/Field/FieldSpec.php +++ b/library/Director/Field/FieldSpec.php @@ -1,6 +1,5 @@ set_if_format === 'string' || $arg->set_if_format === null) + if ( + ($arg->set_if_format === 'string' || $arg->set_if_format === null) && $val = self::getMacroIfStringIsSingleMacro($arg->set_if) ) { $this->addSuggestion($val, $arg->description, $this->booleans); diff --git a/library/Director/Filter/FilterEnrichment.php b/library/Director/Filter/FilterEnrichment.php index c726f766..e722cccc 100644 --- a/library/Director/Filter/FilterEnrichment.php +++ b/library/Director/Filter/FilterEnrichment.php @@ -16,7 +16,8 @@ class FilterEnrichment } } elseif ($filter instanceof FilterChain) { foreach ($filter->filters() as $subFilter) { - if ($subFilter instanceof FilterExpression + if ( + $subFilter instanceof FilterExpression && CidrExpression::isCidrFormat($subFilter->getExpression()) ) { $filter->replaceById($subFilter->getId(), CidrExpression::fromExpression($subFilter)); diff --git a/library/Director/Hook/ImportSourceHook.php b/library/Director/Hook/ImportSourceHook.php index dba1c877..fe45a50e 100644 --- a/library/Director/Hook/ImportSourceHook.php +++ b/library/Director/Hook/ImportSourceHook.php @@ -48,7 +48,7 @@ abstract class ImportSourceHook } /** @var ImportSourceHook $obj */ - $obj = new $className; + $obj = new $className(); $obj->setSettings($settings); return $obj; } @@ -77,7 +77,7 @@ abstract class ImportSourceHook ); } /** @var ImportSourceHook $obj */ - $obj = new $source->provider_class; + $obj = new $source->provider_class(); $obj->setSettings($settings); return $obj; diff --git a/library/Director/IcingaConfig/AssignRenderer.php b/library/Director/IcingaConfig/AssignRenderer.php index 495ad1ef..825ea6b8 100644 --- a/library/Director/IcingaConfig/AssignRenderer.php +++ b/library/Director/IcingaConfig/AssignRenderer.php @@ -144,7 +144,8 @@ class AssignRenderer if (is_string($rawExpression) && ctype_digit($rawExpression)) { // TODO: doing this for compat reasons, should work for all filters - if ($filter instanceof FilterEqualOrGreaterThan + if ( + $filter instanceof FilterEqualOrGreaterThan || $filter instanceof FilterGreaterThan || $filter instanceof FilterEqualOrLessThan || $filter instanceof FilterLessThan diff --git a/library/Director/IcingaConfig/ExtensibleSet.php b/library/Director/IcingaConfig/ExtensibleSet.php index d52a30e4..28d9f1a0 100644 --- a/library/Director/IcingaConfig/ExtensibleSet.php +++ b/library/Director/IcingaConfig/ExtensibleSet.php @@ -46,7 +46,7 @@ class ExtensibleSet public static function forIcingaObject(IcingaObject $object, $propertyName) { - $set = new static; + $set = new static(); $set->object = $object; $set->propertyName = $propertyName; @@ -118,7 +118,7 @@ class ExtensibleSet if ($this->fromDb === null) { return null; } - + $old = $this->fromDb; if ($old['override'] !== null) { @@ -164,7 +164,8 @@ class ExtensibleSet return false; } else { - if ($this->ownValues === null + if ( + $this->ownValues === null && empty($this->plusValues) && empty($this->minusValues) ) { diff --git a/library/Director/IcingaConfig/IcingaConfigHelper.php b/library/Director/IcingaConfig/IcingaConfigHelper.php index 2310c9f1..0c314a3d 100644 --- a/library/Director/IcingaConfig/IcingaConfigHelper.php +++ b/library/Director/IcingaConfig/IcingaConfigHelper.php @@ -3,6 +3,7 @@ namespace Icinga\Module\Director\IcingaConfig; use InvalidArgumentException; + use function ctype_digit; use function explode; use function floor; diff --git a/library/Director/Import/Sync.php b/library/Director/Import/Sync.php index 2957433f..613e7614 100644 --- a/library/Director/Import/Sync.php +++ b/library/Director/Import/Sync.php @@ -411,11 +411,13 @@ class Sync foreach ($objects as $object) { if ($object instanceof IcingaService) { - if (strstr($destinationKeyPattern, '${host}') + if ( + strstr($destinationKeyPattern, '${host}') && $object->get('host_id') === null ) { continue; - } elseif (strstr($destinationKeyPattern, '${service_set}') + } elseif ( + strstr($destinationKeyPattern, '${service_set}') && $object->get('service_set_id') === null ) { continue; @@ -450,7 +452,8 @@ class Sync if ($ruleObjectType === 'service' || $ruleObjectType === 'serviceSet') { foreach ($this->syncProperties as $prop) { $configuredObjectType = $prop->get('source_expression'); - if ($prop->get('destination_field') === 'object_type' + if ( + $prop->get('destination_field') === 'object_type' && ( $configuredObjectType === 'template' || ($configuredObjectType === 'apply' && $ruleObjectType === 'serviceSet') @@ -659,10 +662,12 @@ class Sync protected function getHostGroupMembershipResolver() { if ($this->hostGroupMembershipResolver === null) { - if (in_array( - $this->rule->get('object_type'), - ['host', 'hostgroup'] - )) { + if ( + in_array( + $this->rule->get('object_type'), + ['host', 'hostgroup'] + ) + ) { $this->hostGroupMembershipResolver = new HostGroupMembershipResolver( $this->db ); @@ -788,7 +793,8 @@ class Sync switch ($policy) { case 'override': - if ($object instanceof IcingaHost + if ( + $object instanceof IcingaHost && !in_array('api_key', $this->rule->getSyncProperties()) ) { $this->objects[$key]->replaceWith($object, ['api_key']); diff --git a/library/Director/Integration/Icingadb/IcingadbBackend.php b/library/Director/Integration/Icingadb/IcingadbBackend.php index 874cddde..6e45672a 100644 --- a/library/Director/Integration/Icingadb/IcingadbBackend.php +++ b/library/Director/Integration/Icingadb/IcingadbBackend.php @@ -47,7 +47,8 @@ class IcingadbBackend implements BackendInterface public function canModifyHost(?string $hostName): bool { - if ($hostName === null + if ( + $hostName === null || ! $this->getAuth()->hasPermission(Permission::ICINGADB_HOSTS) ) { return false; @@ -60,7 +61,8 @@ class IcingadbBackend implements BackendInterface public function canModifyService(?string $hostName, ?string $serviceName): bool { - if ($hostName === null + if ( + $hostName === null || $serviceName === null || ! $this->getAuth()->hasPermission(Permission::ICINGADB_SERVICES) ) { diff --git a/library/Director/Objects/DirectorDatafield.php b/library/Director/Objects/DirectorDatafield.php index ced6218a..7791711a 100644 --- a/library/Director/Objects/DirectorDatafield.php +++ b/library/Director/Objects/DirectorDatafield.php @@ -207,11 +207,12 @@ class DirectorDatafield extends DbObjectWithSettings } /** @var DataTypeHook $dataType */ - $dataType = new $className; + $dataType = new $className(); $dataType->setSettings($this->getSettings()); $el = $dataType->getFormElement($name, $form); - if ($this->getSetting('icinga_type') !== 'command' + if ( + $this->getSetting('icinga_type') !== 'command' && $this->getSetting('is_required') === 'y' ) { $el->setRequired(true); diff --git a/library/Director/Objects/DirectorDatalist.php b/library/Director/Objects/DirectorDatalist.php index 1bb821b4..b9b3ac33 100644 --- a/library/Director/Objects/DirectorDatalist.php +++ b/library/Director/Objects/DirectorDatalist.php @@ -95,7 +95,7 @@ class DirectorDatalist extends DbObject implements ExportInterface $db = $this->getDb(); $dataFieldsCheck = $db->select() - ->from(['df' =>'director_datafield'], ['varname']) + ->from(['df' => 'director_datafield'], ['varname']) ->join( ['dfs' => 'director_datafield_setting'], 'dfs.datafield_id = df.id AND dfs.setting_name = \'datalist_id\'', @@ -114,7 +114,7 @@ class DirectorDatalist extends DbObject implements ExportInterface } $syncCheck = $db->select() - ->from(['sp' =>'sync_property'], ['source_expression']) + ->from(['sp' => 'sync_property'], ['source_expression']) ->where('sp.destination_field = ?', 'list_id') ->where('sp.source_expression = ?', $id); diff --git a/library/Director/Objects/DirectorJob.php b/library/Director/Objects/DirectorJob.php index 2a18d523..aadcabc0 100644 --- a/library/Director/Objects/DirectorJob.php +++ b/library/Director/Objects/DirectorJob.php @@ -70,7 +70,7 @@ class DirectorJob extends DbObjectWithSettings implements ExportInterface, Insta { if ($this->job === null) { $class = $this->get('job_class'); - $this->job = new $class; + $this->job = new $class(); $this->job->setDb($this->connection); $this->job->setDefinition($this); } @@ -207,7 +207,7 @@ class DirectorJob extends DbObjectWithSettings implements ExportInterface, Insta protected static function existsWithNameAndId($name, $id, Db $connection) { $db = $connection->getDbAdapter(); - $dummy = new static; + $dummy = new static(); $idCol = $dummy->autoincKeyName; $keyCol = $dummy->keyName; diff --git a/library/Director/Objects/IcingaArguments.php b/library/Director/Objects/IcingaArguments.php index 22bf9142..de5a6e37 100644 --- a/library/Director/Objects/IcingaArguments.php +++ b/library/Director/Objects/IcingaArguments.php @@ -216,10 +216,12 @@ class IcingaArguments implements Iterator, Countable, IcingaConfigRenderer $this->set($arg, $val); } - foreach (array_diff( - array_keys($this->arguments), - array_keys($arguments) - ) as $arg) { + foreach ( + array_diff( + array_keys($this->arguments), + array_keys($arguments) + ) as $arg + ) { if ($this->arguments[$arg]->hasBeenLoadedFromDb()) { $this->arguments[$arg]->markForRemoval(); $this->modified = true; diff --git a/library/Director/Objects/IcingaCommand.php b/library/Director/Objects/IcingaCommand.php index 8c5aed0e..72d05798 100644 --- a/library/Director/Objects/IcingaCommand.php +++ b/library/Director/Objects/IcingaCommand.php @@ -222,8 +222,10 @@ class IcingaCommand extends IcingaObject implements ObjectWithArguments, ExportI $inherited = $this->getInheritedProperties(); - if ($this->get('is_string') === 'y' || ($this->get('is_string') === null - && property_exists($inherited, 'is_string') && $inherited->is_string === 'y')) { + if ( + $this->get('is_string') === 'y' || ($this->get('is_string') === null + && property_exists($inherited, 'is_string') && $inherited->is_string === 'y') + ) { return c::renderKeyValue('command', $prefix . c::renderString($command)); } else { $parts = preg_split('/\s+/', $command, -1, PREG_SPLIT_NO_EMPTY); @@ -267,11 +269,11 @@ class IcingaCommand extends IcingaObject implements ObjectWithArguments, ExportI if (preg_match('~^(\$USER\d+\$/?)(.+)$~', $command)) { // should be fine, since the user decided to use a macro } elseif (! $this->isAbsolutePath($command)) { - $command = '$USER1$/'.$command; + $command = '$USER1$/' . $command; } return c1::renderKeyValue( - $this->getLegacyObjectType().'_line', + $this->getLegacyObjectType() . '_line', c1::renderString($command) ); } diff --git a/library/Director/Objects/IcingaDependency.php b/library/Director/Objects/IcingaDependency.php index abd92e62..9f532b36 100644 --- a/library/Director/Objects/IcingaDependency.php +++ b/library/Director/Objects/IcingaDependency.php @@ -408,7 +408,8 @@ class IcingaDependency extends IcingaObject implements ExportInterface public function renderChild_service_id() { // @codingStandardsIgnoreEnd - if ($this->hasBeenAssignedToServiceTemplate() + if ( + $this->hasBeenAssignedToServiceTemplate() || $this->hasBeenAssignedToHostTemplateService() || $this->hasBeenAssignedToServiceApply() ) { @@ -467,7 +468,8 @@ class IcingaDependency extends IcingaObject implements ExportInterface public function isApplyRule() { - if ($this->hasBeenAssignedToHostTemplate() + if ( + $this->hasBeenAssignedToHostTemplate() || $this->hasBeenAssignedToServiceTemplate() || $this->hasBeenAssignedToServiceApply() ) { @@ -612,7 +614,8 @@ class IcingaDependency extends IcingaObject implements ExportInterface $related = parent::getRelatedProperty($key); // handle special case for plain string parent service on Dependency // Apply rules - if ($related === null + if ( + $related === null && $key === 'parent_service' && ( $this->get('parent_service_by_name') diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index 3b6236db..fec1dde2 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -614,7 +614,8 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer return true; } - if ($this instanceof ObjectWithArguments + if ( + $this instanceof ObjectWithArguments && $this->gotArguments() && $this->arguments()->hasBeenModified() ) { @@ -758,8 +759,10 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer return $this; } - if ($this instanceof ObjectWithArguments - && substr($key, 0, 10) === 'arguments.') { + if ( + $this instanceof ObjectWithArguments + && substr($key, 0, 10) === 'arguments.' + ) { $this->arguments()->set(substr($key, 10), $value); return $this; } @@ -1764,7 +1767,8 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer $deploymentMode = $config->getDeploymentMode(); if ($deploymentMode === 'active-passive') { - if ($this->getSingleResolvedProperty('zone_id') + if ( + $this->getSingleResolvedProperty('zone_id') && array_key_exists('enable_active_checks', $this->defaultProperties) ) { $passive = clone($this); @@ -2115,7 +2119,8 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer ); } - if (substr($key, -3) === '_id' + if ( + substr($key, -3) === '_id' && $this->hasRelation($relKey = substr($key, 0, -3)) ) { return $this->renderRelationProperty($relKey, $value); @@ -2173,7 +2178,8 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer ); } - if (substr($key, -3) === '_id' + if ( + substr($key, -3) === '_id' && $this->hasRelation($relKey = substr($key, 0, -3)) ) { return $this->renderLegacyRelationProperty($relKey, $value); @@ -2401,7 +2407,8 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer $str = ''; // Set notification settings for the object to suppress warnings - if (array_key_exists('enable_notifications', $this->defaultProperties) + if ( + array_key_exists('enable_notifications', $this->defaultProperties) && $this->isTemplate() ) { $str .= c1::renderKeyValue('notification_period', 'notification_none'); @@ -2411,7 +2418,8 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer // force rendering of check_command when ARG1 is set if ($this->supportsCustomVars() && array_key_exists('check_command_id', $this->defaultProperties)) { - if ($this->get('check_command') === null + if ( + $this->get('check_command') === null && $this->vars()->get('ARG1') !== null ) { $command = $this->getResolvedRelated('check_command'); @@ -2701,7 +2709,8 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer } } - if (PrefetchCache::shouldBeUsed() + if ( + PrefetchCache::shouldBeUsed() && $query === null && $keyColumn === static::getKeyColumnName() ) { @@ -3119,7 +3128,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer public function getOnDeleteUrl() { - $plural= preg_replace('/cys$/', 'cies', strtolower($this->getShortTableName()) . 's'); + $plural = preg_replace('/cys$/', 'cies', strtolower($this->getShortTableName()) . 's'); return 'director/' . $plural; } diff --git a/library/Director/Objects/IcingaObjectGroups.php b/library/Director/Objects/IcingaObjectGroups.php index 8683c778..3de9f1d8 100644 --- a/library/Director/Objects/IcingaObjectGroups.php +++ b/library/Director/Objects/IcingaObjectGroups.php @@ -342,7 +342,7 @@ class IcingaObjectGroups implements Iterator, Countable, IcingaConfigRenderer protected function getGroupClass() { - return __NAMESPACE__ . '\\Icinga' .ucfirst($this->object->getShortTableName()) . 'Group'; + return __NAMESPACE__ . '\\Icinga' . ucfirst($this->object->getShortTableName()) . 'Group'; } public static function loadForStoredObject(IcingaObject $object) @@ -380,7 +380,7 @@ class IcingaObjectGroups implements Iterator, Countable, IcingaConfigRenderer } $type = $this->object->getLegacyObjectType(); - return c1::renderKeyValue($type.'groups', c1::renderArray($groups)); + return c1::renderKeyValue($type . 'groups', c1::renderArray($groups)); } public function __toString() diff --git a/library/Director/Objects/IcingaScheduledDowntimeRange.php b/library/Director/Objects/IcingaScheduledDowntimeRange.php index 6280990b..a39e07be 100644 --- a/library/Director/Objects/IcingaScheduledDowntimeRange.php +++ b/library/Director/Objects/IcingaScheduledDowntimeRange.php @@ -47,7 +47,8 @@ class IcingaScheduledDowntimeRange extends DbObject { $hBegin = $mBegin = $hEnd = $mEnd = null; if (sscanf($rangeString, '%2d:%2d-%2d:%2d', $hBegin, $mBegin, $hEnd, $mEnd) === 4) { - if ($this->timeFromHourMin($hBegin, $mBegin, $now) <= $now + if ( + $this->timeFromHourMin($hBegin, $mBegin, $now) <= $now && $this->timeFromHourMin($hEnd, $mEnd, $now) >= $now ) { return true; diff --git a/library/Director/Objects/IcingaService.php b/library/Director/Objects/IcingaService.php index cbf9ca52..9b51619b 100644 --- a/library/Director/Objects/IcingaService.php +++ b/library/Director/Objects/IcingaService.php @@ -307,7 +307,8 @@ class IcingaService extends IcingaObject implements ExportInterface $str = parent::toLegacyConfigString(); - if (! $this->isDisabled() + if ( + ! $this->isDisabled() && $this->get('host_id') && $this->getRelated('host')->isDisabled() ) { @@ -329,7 +330,8 @@ class IcingaService extends IcingaObject implements ExportInterface } $str = parent::toConfigString(); - if (! $this->isDisabled() + if ( + ! $this->isDisabled() && $this->get('host_id') && $this->getRelated('host')->isDisabled() ) { @@ -346,7 +348,8 @@ class IcingaService extends IcingaObject implements ExportInterface */ protected function renderObjectHeader() { - if ($this->isApplyRule() + if ( + $this->isApplyRule() && !$this->hasBeenAssignedToHostTemplate() && $this->get('apply_for') !== null ) { @@ -609,7 +612,8 @@ class IcingaService extends IcingaObject implements ExportInterface { $where = parent::createWhere(); if (! $this->hasBeenLoadedFromDb()) { - if (null === $this->get('service_set_id') + if ( + null === $this->get('service_set_id') && null === $this->get('host_id') && null === $this->get('id') ) { @@ -717,7 +721,8 @@ class IcingaService extends IcingaObject implements ExportInterface protected function beforeStore() { parent::beforeStore(); - if ($this->isObject() + if ( + $this->isObject() && $this->get('service_set_id') === null && $this->get('host_id') === null ) { diff --git a/library/Director/Objects/IcingaTimePeriodRange.php b/library/Director/Objects/IcingaTimePeriodRange.php index 55c1a3ee..638fce21 100644 --- a/library/Director/Objects/IcingaTimePeriodRange.php +++ b/library/Director/Objects/IcingaTimePeriodRange.php @@ -47,7 +47,8 @@ class IcingaTimePeriodRange extends DbObject { $hBegin = $mBegin = $hEnd = $mEnd = null; if (sscanf($rangeString, '%2d:%2d-%2d:%2d', $hBegin, $mBegin, $hEnd, $mEnd) === 4) { - if ($this->timeFromHourMin($hBegin, $mBegin, $now) <= $now + if ( + $this->timeFromHourMin($hBegin, $mBegin, $now) <= $now && $this->timeFromHourMin($hEnd, $mEnd, $now) >= $now ) { return true; diff --git a/library/Director/Objects/IcingaTimePeriodRanges.php b/library/Director/Objects/IcingaTimePeriodRanges.php index b18437d5..724f6dbd 100644 --- a/library/Director/Objects/IcingaTimePeriodRanges.php +++ b/library/Director/Objects/IcingaTimePeriodRanges.php @@ -27,7 +27,7 @@ class IcingaTimePeriodRanges extends IcingaRanges implements Iterator, Countable ); } if ($out !== '') { - $out = "\n".$out; + $out = "\n" . $out; } return $out; diff --git a/library/Director/Objects/ImportRowModifier.php b/library/Director/Objects/ImportRowModifier.php index afebbad4..8386649b 100644 --- a/library/Director/Objects/ImportRowModifier.php +++ b/library/Director/Objects/ImportRowModifier.php @@ -45,7 +45,7 @@ class ImportRowModifier extends DbObjectWithSettings implements InstantiatedViaH $class )); } - $obj = new $class; + $obj = new $class(); $obj->setSettings($this->getSettings()); $obj->setPropertyName($this->get('property_name')); $obj->setTargetProperty($this->get('target_property')); diff --git a/library/Director/Objects/ImportSource.php b/library/Director/Objects/ImportSource.php index 7477472e..24a6c132 100644 --- a/library/Director/Objects/ImportSource.php +++ b/library/Director/Objects/ImportSource.php @@ -132,7 +132,7 @@ class ImportSource extends DbObjectWithSettings implements ExportInterface protected static function existsWithNameAndId($name, $id, Db $connection) { $db = $connection->getDbAdapter(); - $dummy = new static; + $dummy = new static(); $idCol = $dummy->autoincKeyName; $keyCol = $dummy->keyName; diff --git a/library/Director/Objects/SyncRule.php b/library/Director/Objects/SyncRule.php index 270a8826..3d5cdf41 100644 --- a/library/Director/Objects/SyncRule.php +++ b/library/Director/Objects/SyncRule.php @@ -487,7 +487,7 @@ class SyncRule extends DbObject implements ExportInterface protected static function existsWithNameAndId($name, $id, Db $connection) { $db = $connection->getDbAdapter(); - $dummy = new static; + $dummy = new static(); $idCol = $dummy->autoincKeyName; $keyCol = $dummy->keyName; diff --git a/library/Director/PropertyModifier/PropertyModifierArrayUnique.php b/library/Director/PropertyModifier/PropertyModifierArrayUnique.php index e3446f9d..92702ebe 100644 --- a/library/Director/PropertyModifier/PropertyModifierArrayUnique.php +++ b/library/Director/PropertyModifier/PropertyModifierArrayUnique.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Director\PropertyModifier; use Icinga\Exception\InvalidPropertyException; use Icinga\Module\Director\Hook\PropertyModifierHook; + use function array_unique; use function array_values; use function is_array; diff --git a/library/Director/PropertyModifier/PropertyModifierFromAdSid.php b/library/Director/PropertyModifier/PropertyModifierFromAdSid.php index ee306e32..44905ebe 100644 --- a/library/Director/PropertyModifier/PropertyModifierFromAdSid.php +++ b/library/Director/PropertyModifier/PropertyModifierFromAdSid.php @@ -27,10 +27,10 @@ class PropertyModifierFromAdSid extends PropertyModifierHook $sidHex = unpack('H*hex', $value); $sidHex = $sidHex['hex']; $subAuths = implode('-', unpack('H2/H2/n/N/V*', $sid)); - + $revLevel = hexdec(substr($sidHex, 0, 2)); $authIdent = hexdec(substr($sidHex, 4, 12)); - + return sprintf('S-%s-%s-%s', $revLevel, $authIdent, $subAuths); } } diff --git a/library/Director/PropertyModifier/PropertyModifierFromLatin1.php b/library/Director/PropertyModifier/PropertyModifierFromLatin1.php index 272956c7..1f878339 100644 --- a/library/Director/PropertyModifier/PropertyModifierFromLatin1.php +++ b/library/Director/PropertyModifier/PropertyModifierFromLatin1.php @@ -3,6 +3,7 @@ namespace Icinga\Module\Director\PropertyModifier; use Icinga\Module\Director\Hook\PropertyModifierHook; + use function iconv; class PropertyModifierFromLatin1 extends PropertyModifierHook diff --git a/library/Director/PropertyModifier/PropertyModifierNegateBoolean.php b/library/Director/PropertyModifier/PropertyModifierNegateBoolean.php index e60d6929..95833776 100644 --- a/library/Director/PropertyModifier/PropertyModifierNegateBoolean.php +++ b/library/Director/PropertyModifier/PropertyModifierNegateBoolean.php @@ -3,6 +3,7 @@ namespace Icinga\Module\Director\PropertyModifier; use Icinga\Module\Director\Hook\PropertyModifierHook; + use function ipl\Stdlib\get_php_type; class PropertyModifierNegateBoolean extends PropertyModifierHook diff --git a/library/Director/PropertyModifier/PropertyModifierParseURL.php b/library/Director/PropertyModifier/PropertyModifierParseURL.php index ce7c81be..da43ac0c 100644 --- a/library/Director/PropertyModifier/PropertyModifierParseURL.php +++ b/library/Director/PropertyModifier/PropertyModifierParseURL.php @@ -8,7 +8,6 @@ use Icinga\Module\Director\Web\Form\QuickForm; class PropertyModifierParseURL extends PropertyModifierHook { - /** * Array with possible components that can be returned from URL. */ diff --git a/library/Director/PropertyModifier/PropertyModifierReplaceNull.php b/library/Director/PropertyModifier/PropertyModifierReplaceNull.php index d6f9fd34..5fa5452c 100644 --- a/library/Director/PropertyModifier/PropertyModifierReplaceNull.php +++ b/library/Director/PropertyModifier/PropertyModifierReplaceNull.php @@ -7,12 +7,11 @@ use Icinga\Module\Director\Web\Form\QuickForm; class PropertyModifierReplaceNull extends PropertyModifierHook { - public function getName() { return 'Replace null value with String'; } - + public static function addSettingsFormFields(QuickForm $form) { $form->addElement('text', 'string', [ diff --git a/library/Director/ProvidedHook/Icingadb/IcingadbSupport.php b/library/Director/ProvidedHook/Icingadb/IcingadbSupport.php index 5a593046..90bfc758 100644 --- a/library/Director/ProvidedHook/Icingadb/IcingadbSupport.php +++ b/library/Director/ProvidedHook/Icingadb/IcingadbSupport.php @@ -6,5 +6,4 @@ use Icinga\Module\Icingadb\Hook\IcingadbSupportHook; class IcingadbSupport extends IcingadbSupportHook { - } diff --git a/library/Director/Resolver/HostServiceBlacklist.php b/library/Director/Resolver/HostServiceBlacklist.php index 606855a1..59f39463 100644 --- a/library/Director/Resolver/HostServiceBlacklist.php +++ b/library/Director/Resolver/HostServiceBlacklist.php @@ -80,7 +80,8 @@ class HostServiceBlacklist public function getPreLoadedMappingsForService(IcingaService $service) { - if ($this->mappings !== null + if ( + $this->mappings !== null && array_key_exists($service->get('id'), $this->mappings) ) { return $this->mappings[$service->get('id')]; diff --git a/library/Director/Resolver/TemplateTree.php b/library/Director/Resolver/TemplateTree.php index bf941e28..e1c1cfcf 100644 --- a/library/Director/Resolver/TemplateTree.php +++ b/library/Director/Resolver/TemplateTree.php @@ -137,7 +137,8 @@ class TemplateTree public function getAncestorsFor(IcingaObject $object) { - if ($object->hasBeenModified() + if ( + $object->hasBeenModified() && $object->gotImports() && $object->imports()->hasBeenModified() ) { diff --git a/library/Director/Test/SyncTest.php b/library/Director/Test/SyncTest.php index d118eeaa..40034aee 100644 --- a/library/Director/Test/SyncTest.php +++ b/library/Director/Test/SyncTest.php @@ -14,9 +14,9 @@ use Icinga\Module\Director\Objects\SyncRule; abstract class SyncTest extends BaseTestCase { protected $objectType; - + protected $keyColumn; - + /** @var ImportSource */ protected $source; diff --git a/library/Director/Test/TestSuiteStyle.php b/library/Director/Test/TestSuiteStyle.php index babd43c5..d334b56c 100644 --- a/library/Director/Test/TestSuiteStyle.php +++ b/library/Director/Test/TestSuiteStyle.php @@ -59,7 +59,7 @@ class TestSuiteStyle extends TestSuite `$cmd`; echo $cmd . "\n"; - echo $out ."\n"; + echo $out . "\n"; echo file_get_contents($out); unlink($out); } diff --git a/library/Director/Web/Controller/ActionController.php b/library/Director/Web/Controller/ActionController.php index e851d82d..568df350 100644 --- a/library/Director/Web/Controller/ActionController.php +++ b/library/Director/Web/Controller/ActionController.php @@ -50,7 +50,8 @@ abstract class ActionController extends Controller implements ControlsAndContent */ public function init() { - if (! $this->getRequest()->isApiRequest() + if ( + ! $this->getRequest()->isApiRequest() && $this->Config()->get('frontend', 'disabled', 'no') === 'yes' ) { throw new NotFoundError('Not found'); diff --git a/library/Director/Web/Controller/ObjectController.php b/library/Director/Web/Controller/ObjectController.php index 994a7176..7c1acd63 100644 --- a/library/Director/Web/Controller/ObjectController.php +++ b/library/Director/Web/Controller/ObjectController.php @@ -174,7 +174,8 @@ abstract class ObjectController extends ActionController $this->tabs()->activate('modify'); $this->addObjectTitle(); // Hint: Service Sets are 'templates' (as long as not being assigned to a host - if ($this->getTableName() !== 'icinga_service_set' + if ( + $this->getTableName() !== 'icinga_service_set' && $object->isTemplate() && $this->showNotInBranch($this->translate('Modifying Templates')) ) { @@ -460,7 +461,8 @@ abstract class ObjectController extends ActionController protected function redirectToPreviewForExternals() { - if ($this->object + if ( + $this->object && $this->object->isExternal() && ! in_array($this->object->getShortTableName(), $this->allowedExternals) ) { @@ -566,7 +568,8 @@ abstract class ObjectController extends ActionController } if ($showHint) { $hasPreferredBranch = $this->hasPreferredBranch(); - if (($hasPreferredBranch || $branch->isBranch()) + if ( + ($hasPreferredBranch || $branch->isBranch()) && $object->isObject() && ! $this->getRequest()->isApiRequest() ) { diff --git a/library/Director/Web/Controller/ObjectsController.php b/library/Director/Web/Controller/ObjectsController.php index c4c96c5b..5b3c8879 100644 --- a/library/Director/Web/Controller/ObjectsController.php +++ b/library/Director/Web/Controller/ObjectsController.php @@ -73,7 +73,8 @@ abstract class ObjectsController extends ActionController { $request = $this->getRequest(); $table = $this->getTable(); - if ($request->getControllerName() === 'services' + if ( + $request->getControllerName() === 'services' && $host = $this->params->get('host') ) { $host = IcingaHost::load($host, $this->db()); diff --git a/library/Director/Web/Form/Element/SimpleNote.php b/library/Director/Web/Form/Element/SimpleNote.php index 3097e117..60590c98 100644 --- a/library/Director/Web/Form/Element/SimpleNote.php +++ b/library/Director/Web/Form/Element/SimpleNote.php @@ -17,7 +17,7 @@ class SimpleNote extends FormElement */ protected $_ignore = true; // @codingStandardsIgnoreEnd - + public function isValid($value, $context = null) { return true; diff --git a/library/Director/Web/Form/Element/StoredPassword.php b/library/Director/Web/Form/Element/StoredPassword.php index fa0545be..4fc13de6 100644 --- a/library/Director/Web/Form/Element/StoredPassword.php +++ b/library/Director/Web/Form/Element/StoredPassword.php @@ -37,7 +37,8 @@ class StoredPassword extends ZfText public function setValue($value) { - if (\is_array($value) && isset($value['_value'], $value['_sent']) + if ( + \is_array($value) && isset($value['_value'], $value['_sent']) && $value['_sent'] === 'y' ) { $value = $sentValue = $value['_value']; diff --git a/library/Director/Web/Form/IcingaObjectFieldLoader.php b/library/Director/Web/Form/IcingaObjectFieldLoader.php index ae00855d..83b1aa6d 100644 --- a/library/Director/Web/Form/IcingaObjectFieldLoader.php +++ b/library/Director/Web/Form/IcingaObjectFieldLoader.php @@ -568,7 +568,7 @@ class IcingaObjectFieldLoader $id = $r->object_id; unset($r->object_id); if (! array_key_exists($id, $result)) { - $result[$id] = new stdClass; + $result[$id] = new stdClass(); } $result[$id]->{$r->varname} = DirectorDatafield::fromDbRow( diff --git a/library/Director/Web/Form/IconHelper.php b/library/Director/Web/Form/IconHelper.php index 3add09bf..df7f6a99 100644 --- a/library/Director/Web/Form/IconHelper.php +++ b/library/Director/Web/Form/IconHelper.php @@ -47,7 +47,7 @@ class IconHelper public static function instance() { if (self::$instance === null) { - self::$instance = new static; + self::$instance = new static(); } return self::$instance; diff --git a/library/Director/Web/Form/QuickBaseForm.php b/library/Director/Web/Form/QuickBaseForm.php index 8d25ffba..2d6a59fb 100644 --- a/library/Director/Web/Form/QuickBaseForm.php +++ b/library/Director/Web/Form/QuickBaseForm.php @@ -78,7 +78,7 @@ abstract class QuickBaseForm extends Zend_Form implements ValidHtml $this->setDefault($name, $value); $el->setValue($value); } - + return $this; } diff --git a/library/Director/Web/Table/ActivityLogTable.php b/library/Director/Web/Table/ActivityLogTable.php index a57b86e7..ad8c6463 100644 --- a/library/Director/Web/Table/ActivityLogTable.php +++ b/library/Director/Web/Table/ActivityLogTable.php @@ -80,7 +80,7 @@ class ActivityLogTable extends IntlZfQueryBasedTable { $this->currentRow = $row; $this->splitByDay($row->ts_change_time); - $action = 'action-' . $row->action. ' '; + $action = 'action-' . $row->action . ' '; if ($row->id > $this->lastDeployedId) { $action .= 'undeployed'; } else { diff --git a/library/Director/Web/Table/DeploymentLogTable.php b/library/Director/Web/Table/DeploymentLogTable.php index 48492188..e367f53c 100644 --- a/library/Director/Web/Table/DeploymentLogTable.php +++ b/library/Director/Web/Table/DeploymentLogTable.php @@ -54,7 +54,8 @@ class DeploymentLogTable extends IntlZfQueryBasedTable $classes = ['notsent']; } - if ($this->activeStageName !== null + if ( + $this->activeStageName !== null && $row->stage_name === $this->activeStageName ) { $classes[] = 'running'; diff --git a/library/Director/Web/Table/IcingaServiceSetServiceTable.php b/library/Director/Web/Table/IcingaServiceSetServiceTable.php index 2c3dbc40..1ea8a28b 100644 --- a/library/Director/Web/Table/IcingaServiceSetServiceTable.php +++ b/library/Director/Web/Table/IcingaServiceSetServiceTable.php @@ -124,7 +124,7 @@ class IcingaServiceSetServiceTable extends ZfQueryBasedTable $url = 'director/host/servicesetservice'; } else { if (is_resource($row->uuid)) { - $row->uuid =stream_get_contents($row->uuid); + $row->uuid = stream_get_contents($row->uuid); } $params = [ diff --git a/library/Director/Web/Table/IntlZfQueryBasedTable.php b/library/Director/Web/Table/IntlZfQueryBasedTable.php index 81ef14c0..d02f6f82 100644 --- a/library/Director/Web/Table/IntlZfQueryBasedTable.php +++ b/library/Director/Web/Table/IntlZfQueryBasedTable.php @@ -43,9 +43,9 @@ abstract class IntlZfQueryBasedTable extends ZfQueryBasedTable $timeFormatter = $this->getDateFormatter(); $timeFormatter->setPattern( - in_array(Locale::getDefault(), ['en_US', 'en_US.UTF-8']) ? 'h:mm:ss a': 'H:mm:ss' + in_array(Locale::getDefault(), ['en_US', 'en_US.UTF-8']) ? 'h:mm:ss a' : 'H:mm:ss' ); - + return $timeFormatter->format((new DateTime())->setTimestamp($timeStamp)); } } diff --git a/library/Director/Web/Table/PropertymodifierTable.php b/library/Director/Web/Table/PropertymodifierTable.php index bf9e4a39..a3d0691c 100644 --- a/library/Director/Web/Table/PropertymodifierTable.php +++ b/library/Director/Web/Table/PropertymodifierTable.php @@ -82,7 +82,7 @@ class PropertymodifierTable extends ZfQueryBasedTable $class = $row->provider_class; try { /** @var ImportSourceHook $hook */ - $hook = new $class; + $hook = new $class(); $caption .= ': ' . $hook->getName(); } catch (Exception $e) { $caption = $this->createErrorCaption($caption, $e); diff --git a/library/Director/Web/Table/TableWithBranchSupport.php b/library/Director/Web/Table/TableWithBranchSupport.php index 9e412c37..3bfec2fb 100644 --- a/library/Director/Web/Table/TableWithBranchSupport.php +++ b/library/Director/Web/Table/TableWithBranchSupport.php @@ -7,7 +7,6 @@ use Ramsey\Uuid\UuidInterface; trait TableWithBranchSupport { - /** @var UuidInterface|null */ protected $branchUuid; diff --git a/library/Director/Web/Tabs/ObjectTabs.php b/library/Director/Web/Tabs/ObjectTabs.php index c355304d..e9142367 100644 --- a/library/Director/Web/Tabs/ObjectTabs.php +++ b/library/Director/Web/Tabs/ObjectTabs.php @@ -102,7 +102,8 @@ class ObjectTabs extends Tabs } // TODO: remove table check once we resolve all group types - if ($object->isGroup() && + if ( + $object->isGroup() && ($object->getShortTableName() === 'hostgroup' || $object->getShortTableName() === 'servicegroup') ) { $this->add('membership', [ @@ -120,7 +121,8 @@ class ObjectTabs extends Tabs ]); } - if ($object->getShortTableName() === 'endpoint' + if ( + $object->getShortTableName() === 'endpoint' && $object->get('apiuser_id') ) { $this->add('inspect', [ diff --git a/library/Director/Web/Tabs/ObjectsTabs.php b/library/Director/Web/Tabs/ObjectsTabs.php index 9d2a7376..c9fd5f71 100644 --- a/library/Director/Web/Tabs/ObjectsTabs.php +++ b/library/Director/Web/Tabs/ObjectsTabs.php @@ -37,14 +37,16 @@ class ObjectsTabs extends Tabs ]); } - if ($auth->hasPermission(Permission::ADMIN) + if ( + $auth->hasPermission(Permission::ADMIN) || ( $object->getShortTableName() === 'notification' && $auth->hasPermission(Permission::NOTIFICATIONS) - ) || ( + ) || ( $object->getShortTableName() === 'scheduled_downtime' && $auth->hasPermission(Permission::SCHEDULED_DOWNTIMES) - )) { + ) + ) { if ($object->supportsApplyRules()) { $this->add('applyrules', [ 'url' => sprintf('director/%s/applyrules', $plType), diff --git a/library/Director/Web/Tree/TemplateTreeRenderer.php b/library/Director/Web/Tree/TemplateTreeRenderer.php index 8b235180..11c5908d 100644 --- a/library/Director/Web/Tree/TemplateTreeRenderer.php +++ b/library/Director/Web/Tree/TemplateTreeRenderer.php @@ -73,7 +73,7 @@ class TemplateTreeRenderer extends BaseHtmlElement $tree['name'], "director/{$type}template/usage", array('name' => $tree['name']), - array('class' => 'icon-' .$type) + array('class' => 'icon-' . $type) )); } diff --git a/library/Director/Web/Widget/ActivityLogInfo.php b/library/Director/Web/Widget/ActivityLogInfo.php index 2b64fd42..7de6eff2 100644 --- a/library/Director/Web/Widget/ActivityLogInfo.php +++ b/library/Director/Web/Widget/ActivityLogInfo.php @@ -227,7 +227,7 @@ class ActivityLogInfo extends HtmlDocument $this->oldProperties = JsonString::decodeOptional($this->entry->old_properties); } if ($this->oldProperties === null) { - $this->oldProperties = new \stdClass; + $this->oldProperties = new \stdClass(); } } @@ -241,7 +241,7 @@ class ActivityLogInfo extends HtmlDocument $this->newProperties = JsonString::decodeOptional($this->entry->new_properties); } if ($this->newProperties === null) { - $this->newProperties = new \stdClass; + $this->newProperties = new \stdClass(); } } @@ -373,10 +373,12 @@ class ActivityLogInfo extends HtmlDocument $this->defaultTab = 'diff'; } - if (in_array($entry->action_name, [ + if ( + in_array($entry->action_name, [ DirectorActivityLog::ACTION_CREATE, DirectorActivityLog::ACTION_MODIFY, - ])) { + ]) + ) { $tabs->add('new', [ 'label' => $this->translate('New object'), 'url' => $url->with(['id' => $entry->id, 'show' => 'new']) @@ -387,10 +389,12 @@ class ActivityLogInfo extends HtmlDocument } } - if (in_array($entry->action_name, [ + if ( + in_array($entry->action_name, [ DirectorActivityLog::ACTION_DELETE, DirectorActivityLog::ACTION_MODIFY, - ])) { + ]) + ) { $tabs->add('old', [ 'label' => $this->translate('Former object'), 'url' => $url->with(['id' => $entry->id, 'show' => 'old']) diff --git a/library/Director/Web/Widget/SyncRunDetails.php b/library/Director/Web/Widget/SyncRunDetails.php index 408e8f6b..5273f997 100644 --- a/library/Director/Web/Widget/SyncRunDetails.php +++ b/library/Director/Web/Widget/SyncRunDetails.php @@ -9,6 +9,7 @@ use Icinga\Module\Director\Objects\SyncRun; use gipfl\IcingaWeb2\Link; use gipfl\Translation\TranslationHelper; use gipfl\IcingaWeb2\Widget\NameValueTable; + use function sprintf; class SyncRunDetails extends NameValueTable diff --git a/run-php5.3.php b/run-php5.3.php index f79cec57..1e49e1bd 100644 --- a/run-php5.3.php +++ b/run-php5.3.php @@ -1,7 +1,6 @@ testIcingaCommand->store($db); - + $this->testHost = IcingaHost::create([ 'object_name' => self::HOST_NAME, 'object_type' => 'object',