Fix `PSR-12` violations

This commit is contained in:
Eric Lippmann 2024-10-22 14:31:14 +02:00
parent 48ad72f9c2
commit 00985429c5
104 changed files with 305 additions and 197 deletions

View File

@ -167,7 +167,7 @@ class SyncruleCommand extends Command
return 'There are pending changes for this Sync Rule. You should' return 'There are pending changes for this Sync Rule. You should'
. ' trigger a new Sync Run.'; . ' trigger a new Sync Run.';
case 'failing': case 'failing':
return 'This Sync Rule failed: '. $rule->get('last_error_message'); return 'This Sync Rule failed: ' . $rule->get('last_error_message');
default: default:
throw new RuntimeException('Invalid sync state: ' . $rule->get('sync_state')); throw new RuntimeException('Invalid sync state: ' . $rule->get('sync_state'));
} }

View File

@ -90,7 +90,7 @@ class CommandController extends ObjectController
$o = $this->object; $o = $this->object;
$this->tabs()->activate('arguments'); $this->tabs()->activate('arguments');
$this->addTitle($this->translate('Command arguments: %s'), $o->getObjectName()); $this->addTitle($this->translate('Command arguments: %s'), $o->getObjectName());
$form = (new IcingaCommandArgumentForm) $form = (new IcingaCommandArgumentForm())
->setBranch($this->getBranch()) ->setBranch($this->getBranch())
->setCommandObject($o); ->setCommandObject($o);
if ($argument = $p->shift('argument')) { if ($argument = $p->shift('argument')) {

View File

@ -482,7 +482,7 @@ class ConfigController extends ActionController
*/ */
protected function deploymentFailed($checksum, $error = null) protected function deploymentFailed($checksum, $error = null)
{ {
$extra = $error ? ': ' . $error: ''; $extra = $error ? ': ' . $error : '';
if ($this->getRequest()->isApiRequest()) { if ($this->getRequest()->isApiRequest()) {
$this->sendJsonError($this->getResponse(), 'Config deployment failed' . $extra); $this->sendJsonError($this->getResponse(), 'Config deployment failed' . $extra);
@ -503,7 +503,8 @@ class ConfigController extends ActionController
{ {
$tabs = $this->tabs(); $tabs = $this->tabs();
if ($this->hasPermission(Permission::DEPLOY) if (
$this->hasPermission(Permission::DEPLOY)
&& $deploymentId = $this->params->get('deployment_id') && $deploymentId = $this->params->get('deployment_id')
) { ) {
$tabs->add('deployment', [ $tabs->add('deployment', [

View File

@ -36,7 +36,8 @@ class HostController extends ObjectController
$host = $this->getHostObject(); $host = $this->getHostObject();
$auth = $this->Auth(); $auth = $this->Auth();
$backend = $this->backend(); $backend = $this->backend();
if ($this->isServiceAction() if (
$this->isServiceAction()
&& $backend->canModifyService($host->getObjectName(), $this->getParam('service')) && $backend->canModifyService($host->getObjectName(), $this->getParam('service'))
) { ) {
return; return;
@ -147,7 +148,8 @@ class HostController extends ObjectController
if ($info && $auth->hasPermission(Permission::HOSTS)) { if ($info && $auth->hasPermission(Permission::HOSTS)) {
$redirectUrl = $info->getUrl(); $redirectUrl = $info->getUrl();
} elseif ($info } elseif (
$info
&& (($backend instanceof Monitoring && $auth->hasPermission(Permission::MONITORING_HOSTS)) && (($backend instanceof Monitoring && $auth->hasPermission(Permission::MONITORING_HOSTS))
|| ($backend instanceof IcingadbBackend && $auth->hasPermission(Permission::ICINGADB_HOSTS)) || ($backend instanceof IcingadbBackend && $auth->hasPermission(Permission::ICINGADB_HOSTS))
) )
@ -593,7 +595,8 @@ class HostController extends ObjectController
$host = $this->object; $host = $this->object;
try { try {
$backend = $this->backend(); $backend = $this->backend();
if ($host instanceof IcingaHost if (
$host instanceof IcingaHost
&& $host->isObject() && $host->isObject()
&& $backend->hasHost($host->getObjectName()) && $backend->hasHost($host->getObjectName())
) { ) {

View File

@ -397,7 +397,7 @@ class SelfServiceController extends ActionController
$params['parent_zone'] = $zoneName; $params['parent_zone'] = $zoneName;
$params['ca_server'] = $master->getObjectName(); $params['ca_server'] = $master->getObjectName();
$params['parent_endpoints'] = $endpointNames; $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) protected function addStringSettingsToParams(Settings $settings, array $keys, array &$params)

View File

@ -29,7 +29,8 @@ class ServiceController extends ObjectController
protected function checkDirectorPermissions() protected function checkDirectorPermissions()
{ {
if ($this->host if (
$this->host
&& $this->object && $this->object
&& $this->backend()->canModifyService($this->host->getObjectName(), $this->object->getObjectName()) && $this->backend()->canModifyService($this->host->getObjectName(), $this->object->getObjectName())
) { ) {
@ -190,7 +191,8 @@ class ServiceController extends ObjectController
} }
try { try {
if ($object->isTemplate() if (
$object->isTemplate()
&& $object->getResolvedProperty('check_command_id') && $object->getResolvedProperty('check_command_id')
) { ) {
$this->view->actionLinks .= ' ' . $this->view->qlink( $this->view->actionLinks .= ' ' . $this->view->qlink(

View File

@ -122,7 +122,7 @@ class SuggestController extends ActionController
protected function suggestServicenames() protected function suggestServicenames()
{ {
$r=array(); $r = array();
$this->assertPermission('director/services'); $this->assertPermission('director/services');
$db = $this->db()->getDbAdapter(); $db = $this->db()->getDbAdapter();
$for_host = $this->getRequest()->getPost('for_host'); $for_host = $this->getRequest()->getPost('for_host');
@ -152,7 +152,7 @@ class SuggestController extends ActionController
$matcher = HostApplyMatches::prepare($tmp_host); $matcher = HostApplyMatches::prepare($tmp_host);
foreach ($this->getAllApplyRules() as $rule) { foreach ($this->getAllApplyRules() as $rule) {
if ($matcher->matchesFilter($rule->filter)) { //TODO if ($matcher->matchesFilter($rule->filter)) { //TODO
$r[]=$rule->name; $r[] = $rule->name;
} }
} }
} }
@ -291,7 +291,7 @@ class SuggestController extends ActionController
$db = $this->db()->getDbAdapter(); $db = $this->db()->getDbAdapter();
$query = $db->select() $query = $db->select()
->from(['f' =>'director_datafield'], []) ->from(['f' => 'director_datafield'], [])
->join( ->join(
['sid' => 'director_datafield_setting'], ['sid' => 'director_datafield_setting'],
'sid.datafield_id = f.id AND sid.setting_name = \'datalist_id\'', 'sid.datafield_id = f.id AND sid.setting_name = \'datalist_id\'',
@ -369,7 +369,7 @@ class SuggestController extends ActionController
protected function getAllApplyRules() protected function getAllApplyRules()
{ {
$allApplyRules=$this->fetchAllApplyRules(); $allApplyRules = $this->fetchAllApplyRules();
foreach ($allApplyRules as $rule) { foreach ($allApplyRules as $rule) {
$rule->filter = Filter::fromQueryString($rule->assign_filter); $rule->filter = Filter::fromQueryString($rule->assign_filter);
} }

View File

@ -65,7 +65,8 @@ class BasketUploadForm extends DirectorObjectForm
throw new IcingaException('Got no file'); 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']) || ! is_uploaded_file($_FILES['uploaded_file']['tmp_name'])
) { ) {
$this->addError('Got no uploaded file'); $this->addError('Got no uploaded file');

View File

@ -51,11 +51,13 @@ trait DeployFormsBug7530
]; ];
foreach ($objectTypes as $objectType) { foreach ($objectTypes as $objectType) {
if ((int) $db->fetchOne( if (
$db->select() (int) $db->fetchOne(
$db->select()
->from($objectType, 'COUNT(*)') ->from($objectType, 'COUNT(*)')
->where('zone_id IN (?)', $zoneIds) ->where('zone_id IN (?)', $zoneIds)
) > 0) { ) > 0
) {
return true; return true;
} }
} }
@ -70,7 +72,8 @@ trait DeployFormsBug7530
$version = $this->api->getVersion(); $version = $this->api->getVersion();
if ($version === null) { if ($version === null) {
throw new \RuntimeException($this->translate('Unable to detect your Icinga 2 Core version')); 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', '<') && \version_compare($version, '2.12.0', '<')
) { ) {
return true; return true;

View File

@ -157,7 +157,7 @@ class DeploymentLinkForm extends DirectorForm
protected function deploymentFailed($checksum, $error = null) protected function deploymentFailed($checksum, $error = null)
{ {
$extra = $error ? ': ' . $error: ''; $extra = $error ? ': ' . $error : '';
if ($this->getRequest()->isApiRequest()) { if ($this->getRequest()->isApiRequest()) {
throw new IcingaException('Not yet'); throw new IcingaException('Not yet');

View File

@ -175,7 +175,7 @@ class DirectorDatafieldForm extends DirectorObjectForm
$error = $e->getMessage(); $error = $e->getMessage();
$types = $this->optionalEnum(array()); $types = $this->optionalEnum(array());
} }
$this->addElement('select', 'datatype', array( $this->addElement('select', 'datatype', array(
'label' => $this->translate('Data type'), 'label' => $this->translate('Data type'),
'description' => $this->translate('Field type'), 'description' => $this->translate('Field type'),

View File

@ -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->object instanceof IcingaServiceSet)
) { ) {
$this->addBoolean('clone_services', [ $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->object->supportsFields()
) { ) {
$this->addBoolean('clone_fields', [ $this->addBoolean('clone_fields', [

View File

@ -209,7 +209,8 @@ class IcingaHostForm extends DirectorObjectForm
*/ */
protected function addGroupsElement() protected function addGroupsElement()
{ {
if ($this->hasHostGroupRestriction() if (
$this->hasHostGroupRestriction()
&& ! $this->getAuth()->hasPermission(Permission::GROUPS_FOR_RESTRICTED_HOSTS) && ! $this->getAuth()->hasPermission(Permission::GROUPS_FOR_RESTRICTED_HOSTS)
) { ) {
return $this; return $this;

View File

@ -282,10 +282,12 @@ class IcingaServiceForm extends DirectorObjectForm
$db = $this->db->getDbAdapter(); $db = $this->db->getDbAdapter();
$host->unsetOverriddenServiceVars($this->object->getObjectName())->store(); $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'), 'host_id' => $host->get('id'),
'service_id' => $service->get('id') 'service_id' => $service->get('id')
])) { ])
) {
$msg = sprintf( $msg = sprintf(
$this->translate('%s has been deactivated on %s'), $this->translate('%s has been deactivated on %s'),
$service->getObjectName(), $service->getObjectName(),

View File

@ -41,8 +41,10 @@ class KickstartForm extends DirectorForm
$this->addResourceConfigElements(); $this->addResourceConfigElements();
$this->addResourceDisplayGroup(); $this->addResourceDisplayGroup();
if (!$this->config()->get('db', 'resource') if (
|| ($this->config()->get('db', 'resource') !== $this->getResourceName())) { !$this->config()->get('db', 'resource')
|| ($this->config()->get('db', 'resource') !== $this->getResourceName())
) {
return; return;
} }
} }
@ -353,8 +355,10 @@ class KickstartForm extends DirectorForm
} }
} }
if ($this->getSubmitLabel() === $this->createDbLabel if (
|| $this->getSubmitLabel() === $this->migrateDbLabel) { $this->getSubmitLabel() === $this->createDbLabel
|| $this->getSubmitLabel() === $this->migrateDbLabel
) {
$this->migrations()->applyPendingMigrations(); $this->migrations()->applyPendingMigrations();
parent::onSuccess(); parent::onSuccess();
} }
@ -448,7 +452,8 @@ class KickstartForm extends DirectorForm
{ {
if ($resourceName = $this->getResourceName()) { if ($resourceName = $this->getResourceName()) {
$resourceConfig = ResourceFactory::getResourceConfig($resourceName); $resourceConfig = ResourceFactory::getResourceConfig($resourceName);
if (!isset($resourceConfig->charset) if (
!isset($resourceConfig->charset)
|| !in_array($resourceConfig->charset, array('utf8', 'utf8mb4', 'UTF8', 'UTF-8')) || !in_array($resourceConfig->charset, array('utf8', 'utf8mb4', 'UTF8', 'UTF-8'))
) { ) {
if ($resource = $this->getElement('resource')) { if ($resource = $this->getElement('resource')) {

View File

@ -1,4 +1,5 @@
<?php <?php
// Avoid complaints about missing namespace and invalid class name // Avoid complaints about missing namespace and invalid class name
// @codingStandardsIgnoreStart // @codingStandardsIgnoreStart

View File

@ -47,7 +47,8 @@ class CoreApi implements DeploymentApiInterface
{ {
$version = $this->getVersion(); $version = $this->getVersion();
if ($version === null || if (
$version === null ||
((version_compare($version, '2.8.2', '>=') && version_compare($version, '2.10.2', '<'))) ((version_compare($version, '2.8.2', '>=') && version_compare($version, '2.10.2', '<')))
) { ) {
$this->client->disconnect(); $this->client->disconnect();
@ -681,7 +682,8 @@ constants
continue; continue;
} }
if (in_array('startup.log', $availableFiles) if (
in_array('startup.log', $availableFiles)
&& in_array('status', $availableFiles) && in_array('status', $availableFiles)
) { ) {
if ($this->getStagedFile($stage, 'status') === '0') { if ($this->getStagedFile($stage, 'status') === '0') {

View File

@ -55,7 +55,8 @@ class LegacyDeploymentApi implements DeploymentApiInterface
continue; continue;
} }
if (in_array('startup.log', $availableFiles) if (
in_array('startup.log', $availableFiles)
&& in_array('status', $availableFiles) && in_array('status', $availableFiles)
) { ) {
$status = $this->getStagedFile($stage, 'status'); $status = $this->getStagedFile($stage, 'status');
@ -91,7 +92,8 @@ class LegacyDeploymentApi implements DeploymentApiInterface
// try to expire old deployments // try to expire old deployments
foreach ($uncollected as $name => $deployment) { foreach ($uncollected as $name => $deployment) {
/** @var DirectorDeploymentLog $deployment */ /** @var DirectorDeploymentLog $deployment */
if ($deployment->get('dump_succeeded') === 'n' if (
$deployment->get('dump_succeeded') === 'n'
|| $deployment->get('startup_succeeded') === null || $deployment->get('startup_succeeded') === null
) { ) {
$start_time = strtotime($deployment->start_time); $start_time = strtotime($deployment->start_time);
@ -106,7 +108,8 @@ class LegacyDeploymentApi implements DeploymentApiInterface
} }
foreach ($this->listPackageStages($packageName) as $stage) { foreach ($this->listPackageStages($packageName) as $stage) {
if (array_key_exists($stage, $uncollected) if (
array_key_exists($stage, $uncollected)
&& $uncollected[$stage]->get('startup_succeeded') === null && $uncollected[$stage]->get('startup_succeeded') === null
) { ) {
continue; continue;
@ -177,7 +180,8 @@ class LegacyDeploymentApi implements DeploymentApiInterface
while ($file = readdir($dh)) { while ($file = readdir($dh)) {
if ($file === '.' || $file === '..') { if ($file === '.' || $file === '..') {
continue; continue;
} elseif (is_dir($this->deploymentPath . DIRECTORY_SEPARATOR . $file) } elseif (
is_dir($this->deploymentPath . DIRECTORY_SEPARATOR . $file)
&& substr($file, 0, 9) === 'director-' && substr($file, 0, 9) === 'director-'
) { ) {
$stages[] = $file; $stages[] = $file;
@ -234,7 +238,7 @@ class LegacyDeploymentApi implements DeploymentApiInterface
// 'module_name' => $moduleName, // 'module_name' => $moduleName,
)); ));
$stage_name = 'director-' .date('Ymd-His'); $stage_name = 'director-' . date('Ymd-His');
$deployment->set('stage_name', $stage_name); $deployment->set('stage_name', $stage_name);
try { try {

View File

@ -17,13 +17,13 @@ class RestApiResponse
public static function fromJsonResult($json) public static function fromJsonResult($json)
{ {
$response = new static; $response = new static();
return $response->parseJsonResult($json); return $response->parseJsonResult($json);
} }
public static function fromErrorMessage($error) public static function fromErrorMessage($error)
{ {
$response = new static; $response = new static();
$response->errorMessage = $error; $response->errorMessage = $error;
return $response; return $response;

View File

@ -183,7 +183,7 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
) )
)->where(sprintf('v.%s = ?', $object->getVarsIdColumn()), $object->get('id')); )->where(sprintf('v.%s = ?', $object->getVarsIdColumn()), $object->get('id'));
$vars = new CustomVariables; $vars = new CustomVariables();
foreach ($db->fetchAll($query) as $row) { foreach ($db->fetchAll($query) as $row) {
$vars->vars[$row->varname] = CustomVariable::fromDbRow($row); $vars->vars[$row->varname] = CustomVariable::fromDbRow($row);
} }
@ -194,7 +194,7 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
public static function forStoredRows($rows) public static function forStoredRows($rows)
{ {
$vars = new CustomVariables; $vars = new CustomVariables();
foreach ($rows as $row) { foreach ($rows as $row) {
$vars->vars[$row->varname] = CustomVariable::fromDbRow($row); $vars->vars[$row->varname] = CustomVariable::fromDbRow($row);
} }
@ -383,7 +383,7 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
} }
if ($out !== '') { if ($out !== '') {
$out = "\n".$out; $out = "\n" . $out;
} }
return $out; return $out;

View File

@ -13,6 +13,7 @@ use React\EventLoop\LoopInterface;
use React\Promise\Deferred; use React\Promise\Deferred;
use RuntimeException; use RuntimeException;
use SplObjectStorage; use SplObjectStorage;
use function React\Promise\reject; use function React\Promise\reject;
use function React\Promise\resolve; use function React\Promise\resolve;

View File

@ -6,6 +6,7 @@ use Exception;
use Icinga\Module\Director\Db; use Icinga\Module\Director\Db;
use Icinga\Module\Director\Objects\DirectorDeploymentLog; use Icinga\Module\Director\Objects\DirectorDeploymentLog;
use React\EventLoop\LoopInterface; use React\EventLoop\LoopInterface;
use function React\Promise\resolve; use function React\Promise\resolve;
class DeploymentChecker implements DbBasedComponent class DeploymentChecker implements DbBasedComponent

View File

@ -10,6 +10,7 @@ use Icinga\Module\Director\Objects\DirectorJob;
use React\ChildProcess\Process; use React\ChildProcess\Process;
use React\EventLoop\LoopInterface; use React\EventLoop\LoopInterface;
use React\Promise\Promise; use React\Promise\Promise;
use function React\Promise\resolve; use function React\Promise\resolve;
class JobRunner implements DbBasedComponent class JobRunner implements DbBasedComponent
@ -139,9 +140,11 @@ class JobRunner implements DbBasedComponent
{ {
$db = $this->db->getDbAdapter(); $db = $this->db->getDbAdapter();
foreach ($db->fetchCol( foreach (
$db->select()->from('director_job', 'id')->where('disabled = ?', 'n') $db->fetchCol(
) as $id) { $db->select()->from('director_job', 'id')->where('disabled = ?', 'n')
) as $id
) {
$this->scheduledIds[] = (int) $id; $this->scheduledIds[] = (int) $id;
}; };
} }

View File

@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Daemon;
use Exception; use Exception;
use Icinga\Module\Director\Db; use Icinga\Module\Director\Db;
use function React\Promise\resolve; use function React\Promise\resolve;
class LogProxy implements DbBasedComponent class LogProxy implements DbBasedComponent

View File

@ -8,6 +8,7 @@ use ipl\Stdlib\EventEmitter;
use React\ChildProcess\Process; use React\ChildProcess\Process;
use React\EventLoop\LoopInterface; use React\EventLoop\LoopInterface;
use React\Promise\Deferred; use React\Promise\Deferred;
use function React\Promise\resolve; use function React\Promise\resolve;
class ProcessList class ProcessList

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Director\Data; namespace Icinga\Module\Director\Data;
use InvalidArgumentException; use InvalidArgumentException;
use function array_diff; use function array_diff;
use function array_key_exists; use function array_key_exists;
use function implode; use function implode;

View File

@ -103,7 +103,8 @@ abstract class DbObject
*/ */
protected function __construct() protected function __construct()
{ {
if ($this->table === null if (
$this->table === null
|| $this->keyName === null || $this->keyName === null
|| $this->defaultProperties === 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) && (string) $value === (string) $this->get($key)
) { ) {
return $this; return $this;
@ -385,7 +387,8 @@ abstract class DbObject
return $this; return $this;
} }
if ($key === 'id' || substr($key, -3) === '_id') { if ($key === 'id' || substr($key, -3) === '_id') {
if ($value !== null if (
$value !== null
&& $this->properties[$key] !== null && $this->properties[$key] !== null
&& (int) $value === (int) $this->properties[$key] && (int) $value === (int) $this->properties[$key]
) { ) {
@ -1206,7 +1209,8 @@ abstract class DbObject
{ {
$class = get_called_class(); $class = get_called_class();
if (static::hasPrefetched($key)) { if (static::hasPrefetched($key)) {
if (is_string($key) if (
is_string($key)
&& array_key_exists($class, self::$prefetchedNames) && array_key_exists($class, self::$prefetchedNames)
&& array_key_exists($key, self::$prefetchedNames[$class]) && array_key_exists($key, self::$prefetchedNames[$class])
) { ) {
@ -1239,7 +1243,8 @@ abstract class DbObject
} }
if (array_key_exists($class, self::$prefetched)) { if (array_key_exists($class, self::$prefetched)) {
if (is_string($key) if (
is_string($key)
&& array_key_exists($class, self::$prefetchedNames) && array_key_exists($class, self::$prefetchedNames)
&& array_key_exists($key, self::$prefetchedNames[$class]) && array_key_exists($key, self::$prefetchedNames[$class])
) { ) {
@ -1283,7 +1288,7 @@ abstract class DbObject
return $prefetched; return $prefetched;
} }
$obj = new static; $obj = new static();
if (self::$dbObjectStore !== null && $obj->hasUuidColumn()) { if (self::$dbObjectStore !== null && $obj->hasUuidColumn()) {
$table = $obj->getTableName(); $table = $obj->getTableName();
assert($connection instanceof Db); assert($connection instanceof Db);
@ -1311,7 +1316,7 @@ abstract class DbObject
return $prefetched; return $prefetched;
} }
/** @var DbObject $obj */ /** @var DbObject $obj */
$obj = new static; $obj = new static();
if (self::$dbObjectStore !== null && $obj->hasUuidColumn()) { if (self::$dbObjectStore !== null && $obj->hasUuidColumn()) {
$table = $obj->getTableName(); $table = $obj->getTableName();
@ -1373,7 +1378,7 @@ abstract class DbObject
$db = $connection->getDbAdapter(); $db = $connection->getDbAdapter();
if ($query === null) { if ($query === null) {
$dummy = new static; $dummy = new static();
$select = $db->select()->from($dummy->table); $select = $db->select()->from($dummy->table);
} else { } else {
$select = $query; $select = $query;
@ -1382,7 +1387,7 @@ abstract class DbObject
foreach ($rows as $row) { foreach ($rows as $row) {
/** @var DbObject $obj */ /** @var DbObject $obj */
$obj = new static; $obj = new static();
$obj->setConnection($connection)->setDbProperties($row); $obj->setConnection($connection)->setDbProperties($row);
if ($keyColumn === null) { if ($keyColumn === null) {
$objects[] = $obj; $objects[] = $obj;
@ -1452,7 +1457,7 @@ abstract class DbObject
} }
/** @var DbObject $obj */ /** @var DbObject $obj */
$obj = new static; $obj = new static();
if (self::$dbObjectStore !== null && $obj->hasUuidColumn()) { if (self::$dbObjectStore !== null && $obj->hasUuidColumn()) {
$table = $obj->getTableName(); $table = $obj->getTableName();
assert($connection instanceof Db); assert($connection instanceof Db);
@ -1471,7 +1476,7 @@ abstract class DbObject
public static function uniqueIdExists(UuidInterface $uuid, DbConnection $connection) public static function uniqueIdExists(UuidInterface $uuid, DbConnection $connection)
{ {
$db = $connection->getDbAdapter(); $db = $connection->getDbAdapter();
$obj = new static; $obj = new static();
$column = $obj->getUuidColumn(); $column = $obj->getUuidColumn();
$query = $db->select() $query = $db->select()
->from($obj->getTableName(), $column) ->from($obj->getTableName(), $column)
@ -1490,7 +1495,7 @@ abstract class DbObject
throw new NotFoundError(sprintf( throw new NotFoundError(sprintf(
'No %s with UUID=%s has been found', 'No %s with UUID=%s has been found',
(new static)->getTableName(), (new static())->getTableName(),
$uuid->toString() $uuid->toString()
)); ));
} }
@ -1498,7 +1503,7 @@ abstract class DbObject
public static function loadWithUniqueId(UuidInterface $uuid, DbConnection $connection): ?DbObject public static function loadWithUniqueId(UuidInterface $uuid, DbConnection $connection): ?DbObject
{ {
$db = $connection->getDbAdapter(); $db = $connection->getDbAdapter();
$obj = new static; $obj = new static();
if (self::$dbObjectStore !== null && $obj->hasUuidColumn()) { if (self::$dbObjectStore !== null && $obj->hasUuidColumn()) {
$table = $obj->getTableName(); $table = $obj->getTableName();

View File

@ -67,7 +67,7 @@ class ServiceSetQueryBuilder
{ {
return $this->db return $this->db
->select() ->select()
->from(['o' =>self::TABLE], []) ->from(['o' => self::TABLE], [])
->joinLeft(['os' => self::SET_TABLE], 'os.id = o.service_set_id', []) ->joinLeft(['os' => self::SET_TABLE], 'os.id = o.service_set_id', [])
->where('os.uuid = ?', $this->connection->quoteBinary($set->getUniqueId()->getBytes())); ->where('os.uuid = ?', $this->connection->quoteBinary($set->getUniqueId()->getBytes()));
} }

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Director\Data; namespace Icinga\Module\Director\Data;
use Icinga\Module\Director\Exception\JsonEncodeException; use Icinga\Module\Director\Exception\JsonEncodeException;
use function json_decode; use function json_decode;
use function json_encode; use function json_encode;
use function json_last_error; use function json_last_error;

View File

@ -120,7 +120,8 @@ class ObjectImporter
*/ */
protected function loadExistingObject(string $implementation, stdClass $plain): ?DbObject 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) && $instance = $implementation::loadWithUniqueId(Uuid::fromString($plain->uuid), $this->db)
) { ) {
return $instance; return $instance;

View File

@ -5,6 +5,7 @@ namespace Icinga\Module\Director\Data;
use InvalidArgumentException; use InvalidArgumentException;
use JsonSerializable; use JsonSerializable;
use stdClass; use stdClass;
use function get_class; use function get_class;
use function gettype; use function gettype;
use function is_array; use function is_array;
@ -21,7 +22,7 @@ class SerializableValue implements Serializable
*/ */
public static function fromSerialization($value) public static function fromSerialization($value)
{ {
$self = new static; $self = new static();
static::assertSerializableValue($value); static::assertSerializableValue($value);
$self->value = $value; $self->value = $value;

View File

@ -21,7 +21,7 @@ class DataTypeBoolean extends DataTypeHook
$vhClass = 'Zend_Form_Decorator_ViewHelper'; $vhClass = 'Zend_Form_Decorator_ViewHelper';
$decorators = $element->getDecorators(); $decorators = $element->getDecorators();
if (array_key_exists($vhClass, $decorators)) { if (array_key_exists($vhClass, $decorators)) {
$decorators[$vhClass] = new ViewHelperRaw; $decorators[$vhClass] = new ViewHelperRaw();
$element->setDecorators($decorators); $element->setDecorators($decorators);
} }

View File

@ -76,10 +76,12 @@ class DataTypeDatalist extends DataTypeHook
*/ */
protected function createEntryIfNotExists(Db $db, $listId, $entry) protected function createEntryIfNotExists(Db $db, $listId, $entry)
{ {
if (! DirectorDatalistEntry::exists([ if (
! DirectorDatalistEntry::exists([
'list_id' => $listId, 'list_id' => $listId,
'entry_name' => $entry, 'entry_name' => $entry,
], $db)) { ], $db)
) {
DirectorDatalistEntry::create([ DirectorDatalistEntry::create([
'list_id' => $listId, 'list_id' => $listId,
'entry_name' => $entry, 'entry_name' => $entry,

View File

@ -12,7 +12,7 @@ class DataTypeNumber extends DataTypeHook
{ {
$element = $form->createElement('text', $name) $element = $form->createElement('text', $name)
->addValidator('int') ->addValidator('int')
->addFilter(new FilterInt); ->addFilter(new FilterInt());
return $element; return $element;
} }

View File

@ -528,7 +528,7 @@ class Db extends DbConnection
{ {
$filters = array( $filters = array(
'methods_execute IN (?)' => array('PluginCheck', 'IcingaCheck'), 'methods_execute IN (?)' => array('PluginCheck', 'IcingaCheck'),
); );
return $this->enumIcingaObjects('command', $filters); return $this->enumIcingaObjects('command', $filters);
} }

View File

@ -40,7 +40,7 @@ class Branch
public static function fromDbRow(stdClass $row) public static function fromDbRow(stdClass $row)
{ {
$self = new static; $self = new static();
if (is_resource($row->uuid)) { if (is_resource($row->uuid)) {
$row->uuid = stream_get_contents($row->uuid); $row->uuid = stream_get_contents($row->uuid);
} }
@ -85,7 +85,7 @@ class Branch
return $hook->getBranchForRequest($request, $store, $auth); return $hook->getBranchForRequest($request, $store, $auth);
} }
return new Branch; return new Branch();
} }
/** /**

View File

@ -49,8 +49,8 @@ class BranchActivity
protected $formerProperties; protected $formerProperties;
public function __construct( public function __construct(
UuidInterface $objectUuid, UuidInterface $objectUuid,
UuidInterface $branchUuid, UuidInterface $branchUuid,
$action, $action,
$objectType, $objectType,
$author, $author,

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Director\Db\Branch; namespace Icinga\Module\Director\Db\Branch;
use Icinga\Module\Director\Data\Json; use Icinga\Module\Director\Data\Json;
use function in_array; use function in_array;
/** /**

View File

@ -25,21 +25,21 @@ class BranchSupport
const TABLE_ICINGA_USERGROUP = 'icinga_usergroup'; const TABLE_ICINGA_USERGROUP = 'icinga_usergroup';
const TABLE_ICINGA_ZONE = 'icinga_zone'; const TABLE_ICINGA_ZONE = 'icinga_zone';
const BRANCHED_TABLE_ICINGA_APIUSER = self::BRANCHED_TABLE_PREFIX. self::TABLE_ICINGA_APIUSER; 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_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_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_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_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_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_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_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_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_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_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_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_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_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_ZONE = self::BRANCHED_TABLE_PREFIX . self::TABLE_ICINGA_ZONE;
const OBJECT_TABLES = [ const OBJECT_TABLES = [
self::TABLE_ICINGA_APIUSER, self::TABLE_ICINGA_APIUSER,

View File

@ -8,6 +8,7 @@ use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Objects\IcingaServiceSet; use Icinga\Module\Director\Objects\IcingaServiceSet;
use Ramsey\Uuid\Uuid; use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface; use Ramsey\Uuid\UuidInterface;
use function is_int; use function is_int;
use function is_resource; use function is_resource;
use function is_string; use function is_string;

View File

@ -8,6 +8,7 @@ use gipfl\ZfDb\Expr;
use Zend_Db_Adapter_Abstract; use Zend_Db_Adapter_Abstract;
use Zend_Db_Adapter_Pdo_Pgsql; use Zend_Db_Adapter_Pdo_Pgsql;
use Zend_Db_Expr; use Zend_Db_Expr;
use function bin2hex; use function bin2hex;
use function is_array; use function is_array;
use function is_resource; use function is_resource;

View File

@ -59,7 +59,8 @@ class IcingaObjectFilterHelper
if ($branchuuid) { if ($branchuuid) {
if ($inheritanceType === self::INHERIT_DIRECT) { if ($inheritanceType === self::INHERIT_DIRECT) {
return $query->where('imports LIKE \'%"' . $template->getObjectName() . '"%\''); return $query->where('imports LIKE \'%"' . $template->getObjectName() . '"%\'');
} elseif ($inheritanceType === self::INHERIT_INDIRECT } elseif (
$inheritanceType === self::INHERIT_INDIRECT
|| $inheritanceType === self::INHERIT_DIRECT_OR_INDIRECT || $inheritanceType === self::INHERIT_DIRECT_OR_INDIRECT
) { ) {
$tree = new TemplateTree($type, $template->getConnection()); $tree = new TemplateTree($type, $template->getConnection());
@ -90,7 +91,8 @@ class IcingaObjectFilterHelper
if ($inheritanceType === self::INHERIT_DIRECT) { if ($inheritanceType === self::INHERIT_DIRECT) {
$sub->where("$i.parent_{$type}_id = ?", $id); $sub->where("$i.parent_{$type}_id = ?", $id);
} elseif ($inheritanceType === self::INHERIT_INDIRECT } elseif (
$inheritanceType === self::INHERIT_INDIRECT
|| $inheritanceType === self::INHERIT_DIRECT_OR_INDIRECT || $inheritanceType === self::INHERIT_DIRECT_OR_INDIRECT
) { ) {
$tree = new TemplateTree($type, $template->getConnection()); $tree = new TemplateTree($type, $template->getConnection());

View File

@ -443,7 +443,8 @@ class BasketSnapshot extends DbObject
foreach ($filter as $column => $value) { foreach ($filter as $column => $value) {
$select->where("$column = ?", $value); $select->where("$column = ?", $value);
} }
} elseif (! $dummy->isGroup() } elseif (
! $dummy->isGroup()
// TODO: this is ugly. // TODO: this is ugly.
&& ! $dummy instanceof IcingaDependency && ! $dummy instanceof IcingaDependency
&& ! $dummy instanceof IcingaTimePeriod && ! $dummy instanceof IcingaTimePeriod

View File

@ -87,9 +87,11 @@ class BasketSnapshotFieldResolver
$db = $this->targetDb->getDbAdapter(); $db = $this->targetDb->getDbAdapter();
foreach ($db->fetchAll( foreach (
$db->select()->from($table)->where("$objectKey = ?", $objectId) $db->fetchAll(
) as $mapping) { $db->select()->from($table)->where("$objectKey = ?", $objectId)
) as $mapping
) {
$existingFields[(int) $mapping->datafield_id] = $mapping; $existingFields[(int) $mapping->datafield_id] = $mapping;
} }
foreach ($object->fields as $field) { foreach ($object->fields as $field) {

View File

@ -5,6 +5,7 @@ namespace Icinga\Module\Director\DirectorObject\Automation;
use Icinga\Module\Director\Core\Json; use Icinga\Module\Director\Core\Json;
use ipl\Html\Error; use ipl\Html\Error;
use RuntimeException; use RuntimeException;
use function array_key_exists; use function array_key_exists;
use function is_array; use function is_array;
use function is_object; use function is_object;

View File

@ -31,7 +31,7 @@ class AppliedServiceInfo implements ServiceInfo
public function __construct($hostName, $serviceName, $serviceApplyRuleId, UuidInterface $uuid) public function __construct($hostName, $serviceName, $serviceApplyRuleId, UuidInterface $uuid)
{ {
$this->hostName = $hostName; $this->hostName = $hostName;
$this->serviceName= $serviceName; $this->serviceName = $serviceName;
$this->serviceApplyRuleId = $serviceApplyRuleId; $this->serviceApplyRuleId = $serviceApplyRuleId;
$this->uuid = $uuid; $this->uuid = $uuid;
} }

View File

@ -30,7 +30,7 @@ class InheritedServiceInfo implements ServiceInfo
{ {
$this->hostName = $hostName; $this->hostName = $hostName;
$this->hostTemplateName = $hostTemplateName; $this->hostTemplateName = $hostTemplateName;
$this->serviceName= $serviceName; $this->serviceName = $serviceName;
$this->uuid = $uuid; $this->uuid = $uuid;
} }

View File

@ -36,13 +36,15 @@ class ServiceFinder
public static function find(IcingaHost $host, $serviceName) public static function find(IcingaHost $host, $serviceName)
{ {
foreach ([ foreach (
[
SingleServiceInfo::class, SingleServiceInfo::class,
InheritedServiceInfo::class, InheritedServiceInfo::class,
ServiceSetServiceInfo::class, ServiceSetServiceInfo::class,
AppliedServiceInfo::class, AppliedServiceInfo::class,
AppliedServiceSetServiceInfo::class, AppliedServiceSetServiceInfo::class,
] as $class) { ] as $class
) {
/** @var ServiceInfo $class */ /** @var ServiceInfo $class */
if ($info = $class::find($host, $serviceName)) { if ($info = $class::find($host, $serviceName)) {
return $info; return $info;

View File

@ -1,6 +1,5 @@
<?php <?php
namespace Icinga\Module\Director\Field; namespace Icinga\Module\Director\Field;
use Icinga\Module\Director\Objects\DirectorDatafield; use Icinga\Module\Director\Objects\DirectorDatafield;

View File

@ -63,7 +63,8 @@ class FormFieldSuggestion
} }
} }
if (($arg->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) && $val = self::getMacroIfStringIsSingleMacro($arg->set_if)
) { ) {
$this->addSuggestion($val, $arg->description, $this->booleans); $this->addSuggestion($val, $arg->description, $this->booleans);

View File

@ -16,7 +16,8 @@ class FilterEnrichment
} }
} elseif ($filter instanceof FilterChain) { } elseif ($filter instanceof FilterChain) {
foreach ($filter->filters() as $subFilter) { foreach ($filter->filters() as $subFilter) {
if ($subFilter instanceof FilterExpression if (
$subFilter instanceof FilterExpression
&& CidrExpression::isCidrFormat($subFilter->getExpression()) && CidrExpression::isCidrFormat($subFilter->getExpression())
) { ) {
$filter->replaceById($subFilter->getId(), CidrExpression::fromExpression($subFilter)); $filter->replaceById($subFilter->getId(), CidrExpression::fromExpression($subFilter));

View File

@ -48,7 +48,7 @@ abstract class ImportSourceHook
} }
/** @var ImportSourceHook $obj */ /** @var ImportSourceHook $obj */
$obj = new $className; $obj = new $className();
$obj->setSettings($settings); $obj->setSettings($settings);
return $obj; return $obj;
} }
@ -77,7 +77,7 @@ abstract class ImportSourceHook
); );
} }
/** @var ImportSourceHook $obj */ /** @var ImportSourceHook $obj */
$obj = new $source->provider_class; $obj = new $source->provider_class();
$obj->setSettings($settings); $obj->setSettings($settings);
return $obj; return $obj;

View File

@ -144,7 +144,8 @@ class AssignRenderer
if (is_string($rawExpression) && ctype_digit($rawExpression)) { if (is_string($rawExpression) && ctype_digit($rawExpression)) {
// TODO: doing this for compat reasons, should work for all filters // TODO: doing this for compat reasons, should work for all filters
if ($filter instanceof FilterEqualOrGreaterThan if (
$filter instanceof FilterEqualOrGreaterThan
|| $filter instanceof FilterGreaterThan || $filter instanceof FilterGreaterThan
|| $filter instanceof FilterEqualOrLessThan || $filter instanceof FilterEqualOrLessThan
|| $filter instanceof FilterLessThan || $filter instanceof FilterLessThan

View File

@ -46,7 +46,7 @@ class ExtensibleSet
public static function forIcingaObject(IcingaObject $object, $propertyName) public static function forIcingaObject(IcingaObject $object, $propertyName)
{ {
$set = new static; $set = new static();
$set->object = $object; $set->object = $object;
$set->propertyName = $propertyName; $set->propertyName = $propertyName;
@ -118,7 +118,7 @@ class ExtensibleSet
if ($this->fromDb === null) { if ($this->fromDb === null) {
return null; return null;
} }
$old = $this->fromDb; $old = $this->fromDb;
if ($old['override'] !== null) { if ($old['override'] !== null) {
@ -164,7 +164,8 @@ class ExtensibleSet
return false; return false;
} else { } else {
if ($this->ownValues === null if (
$this->ownValues === null
&& empty($this->plusValues) && empty($this->plusValues)
&& empty($this->minusValues) && empty($this->minusValues)
) { ) {

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Director\IcingaConfig; namespace Icinga\Module\Director\IcingaConfig;
use InvalidArgumentException; use InvalidArgumentException;
use function ctype_digit; use function ctype_digit;
use function explode; use function explode;
use function floor; use function floor;

View File

@ -411,11 +411,13 @@ class Sync
foreach ($objects as $object) { foreach ($objects as $object) {
if ($object instanceof IcingaService) { if ($object instanceof IcingaService) {
if (strstr($destinationKeyPattern, '${host}') if (
strstr($destinationKeyPattern, '${host}')
&& $object->get('host_id') === null && $object->get('host_id') === null
) { ) {
continue; continue;
} elseif (strstr($destinationKeyPattern, '${service_set}') } elseif (
strstr($destinationKeyPattern, '${service_set}')
&& $object->get('service_set_id') === null && $object->get('service_set_id') === null
) { ) {
continue; continue;
@ -450,7 +452,8 @@ class Sync
if ($ruleObjectType === 'service' || $ruleObjectType === 'serviceSet') { if ($ruleObjectType === 'service' || $ruleObjectType === 'serviceSet') {
foreach ($this->syncProperties as $prop) { foreach ($this->syncProperties as $prop) {
$configuredObjectType = $prop->get('source_expression'); $configuredObjectType = $prop->get('source_expression');
if ($prop->get('destination_field') === 'object_type' if (
$prop->get('destination_field') === 'object_type'
&& ( && (
$configuredObjectType === 'template' $configuredObjectType === 'template'
|| ($configuredObjectType === 'apply' && $ruleObjectType === 'serviceSet') || ($configuredObjectType === 'apply' && $ruleObjectType === 'serviceSet')
@ -659,10 +662,12 @@ class Sync
protected function getHostGroupMembershipResolver() protected function getHostGroupMembershipResolver()
{ {
if ($this->hostGroupMembershipResolver === null) { if ($this->hostGroupMembershipResolver === null) {
if (in_array( if (
$this->rule->get('object_type'), in_array(
['host', 'hostgroup'] $this->rule->get('object_type'),
)) { ['host', 'hostgroup']
)
) {
$this->hostGroupMembershipResolver = new HostGroupMembershipResolver( $this->hostGroupMembershipResolver = new HostGroupMembershipResolver(
$this->db $this->db
); );
@ -788,7 +793,8 @@ class Sync
switch ($policy) { switch ($policy) {
case 'override': case 'override':
if ($object instanceof IcingaHost if (
$object instanceof IcingaHost
&& !in_array('api_key', $this->rule->getSyncProperties()) && !in_array('api_key', $this->rule->getSyncProperties())
) { ) {
$this->objects[$key]->replaceWith($object, ['api_key']); $this->objects[$key]->replaceWith($object, ['api_key']);

View File

@ -47,7 +47,8 @@ class IcingadbBackend implements BackendInterface
public function canModifyHost(?string $hostName): bool public function canModifyHost(?string $hostName): bool
{ {
if ($hostName === null if (
$hostName === null
|| ! $this->getAuth()->hasPermission(Permission::ICINGADB_HOSTS) || ! $this->getAuth()->hasPermission(Permission::ICINGADB_HOSTS)
) { ) {
return false; return false;
@ -60,7 +61,8 @@ class IcingadbBackend implements BackendInterface
public function canModifyService(?string $hostName, ?string $serviceName): bool public function canModifyService(?string $hostName, ?string $serviceName): bool
{ {
if ($hostName === null if (
$hostName === null
|| $serviceName === null || $serviceName === null
|| ! $this->getAuth()->hasPermission(Permission::ICINGADB_SERVICES) || ! $this->getAuth()->hasPermission(Permission::ICINGADB_SERVICES)
) { ) {

View File

@ -207,11 +207,12 @@ class DirectorDatafield extends DbObjectWithSettings
} }
/** @var DataTypeHook $dataType */ /** @var DataTypeHook $dataType */
$dataType = new $className; $dataType = new $className();
$dataType->setSettings($this->getSettings()); $dataType->setSettings($this->getSettings());
$el = $dataType->getFormElement($name, $form); $el = $dataType->getFormElement($name, $form);
if ($this->getSetting('icinga_type') !== 'command' if (
$this->getSetting('icinga_type') !== 'command'
&& $this->getSetting('is_required') === 'y' && $this->getSetting('is_required') === 'y'
) { ) {
$el->setRequired(true); $el->setRequired(true);

View File

@ -95,7 +95,7 @@ class DirectorDatalist extends DbObject implements ExportInterface
$db = $this->getDb(); $db = $this->getDb();
$dataFieldsCheck = $db->select() $dataFieldsCheck = $db->select()
->from(['df' =>'director_datafield'], ['varname']) ->from(['df' => 'director_datafield'], ['varname'])
->join( ->join(
['dfs' => 'director_datafield_setting'], ['dfs' => 'director_datafield_setting'],
'dfs.datafield_id = df.id AND dfs.setting_name = \'datalist_id\'', 'dfs.datafield_id = df.id AND dfs.setting_name = \'datalist_id\'',
@ -114,7 +114,7 @@ class DirectorDatalist extends DbObject implements ExportInterface
} }
$syncCheck = $db->select() $syncCheck = $db->select()
->from(['sp' =>'sync_property'], ['source_expression']) ->from(['sp' => 'sync_property'], ['source_expression'])
->where('sp.destination_field = ?', 'list_id') ->where('sp.destination_field = ?', 'list_id')
->where('sp.source_expression = ?', $id); ->where('sp.source_expression = ?', $id);

View File

@ -70,7 +70,7 @@ class DirectorJob extends DbObjectWithSettings implements ExportInterface, Insta
{ {
if ($this->job === null) { if ($this->job === null) {
$class = $this->get('job_class'); $class = $this->get('job_class');
$this->job = new $class; $this->job = new $class();
$this->job->setDb($this->connection); $this->job->setDb($this->connection);
$this->job->setDefinition($this); $this->job->setDefinition($this);
} }
@ -207,7 +207,7 @@ class DirectorJob extends DbObjectWithSettings implements ExportInterface, Insta
protected static function existsWithNameAndId($name, $id, Db $connection) protected static function existsWithNameAndId($name, $id, Db $connection)
{ {
$db = $connection->getDbAdapter(); $db = $connection->getDbAdapter();
$dummy = new static; $dummy = new static();
$idCol = $dummy->autoincKeyName; $idCol = $dummy->autoincKeyName;
$keyCol = $dummy->keyName; $keyCol = $dummy->keyName;

View File

@ -216,10 +216,12 @@ class IcingaArguments implements Iterator, Countable, IcingaConfigRenderer
$this->set($arg, $val); $this->set($arg, $val);
} }
foreach (array_diff( foreach (
array_keys($this->arguments), array_diff(
array_keys($arguments) array_keys($this->arguments),
) as $arg) { array_keys($arguments)
) as $arg
) {
if ($this->arguments[$arg]->hasBeenLoadedFromDb()) { if ($this->arguments[$arg]->hasBeenLoadedFromDb()) {
$this->arguments[$arg]->markForRemoval(); $this->arguments[$arg]->markForRemoval();
$this->modified = true; $this->modified = true;

View File

@ -222,8 +222,10 @@ class IcingaCommand extends IcingaObject implements ObjectWithArguments, ExportI
$inherited = $this->getInheritedProperties(); $inherited = $this->getInheritedProperties();
if ($this->get('is_string') === 'y' || ($this->get('is_string') === null if (
&& property_exists($inherited, 'is_string') && $inherited->is_string === 'y')) { $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)); return c::renderKeyValue('command', $prefix . c::renderString($command));
} else { } else {
$parts = preg_split('/\s+/', $command, -1, PREG_SPLIT_NO_EMPTY); $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)) { if (preg_match('~^(\$USER\d+\$/?)(.+)$~', $command)) {
// should be fine, since the user decided to use a macro // should be fine, since the user decided to use a macro
} elseif (! $this->isAbsolutePath($command)) { } elseif (! $this->isAbsolutePath($command)) {
$command = '$USER1$/'.$command; $command = '$USER1$/' . $command;
} }
return c1::renderKeyValue( return c1::renderKeyValue(
$this->getLegacyObjectType().'_line', $this->getLegacyObjectType() . '_line',
c1::renderString($command) c1::renderString($command)
); );
} }

View File

@ -408,7 +408,8 @@ class IcingaDependency extends IcingaObject implements ExportInterface
public function renderChild_service_id() public function renderChild_service_id()
{ {
// @codingStandardsIgnoreEnd // @codingStandardsIgnoreEnd
if ($this->hasBeenAssignedToServiceTemplate() if (
$this->hasBeenAssignedToServiceTemplate()
|| $this->hasBeenAssignedToHostTemplateService() || $this->hasBeenAssignedToHostTemplateService()
|| $this->hasBeenAssignedToServiceApply() || $this->hasBeenAssignedToServiceApply()
) { ) {
@ -467,7 +468,8 @@ class IcingaDependency extends IcingaObject implements ExportInterface
public function isApplyRule() public function isApplyRule()
{ {
if ($this->hasBeenAssignedToHostTemplate() if (
$this->hasBeenAssignedToHostTemplate()
|| $this->hasBeenAssignedToServiceTemplate() || $this->hasBeenAssignedToServiceTemplate()
|| $this->hasBeenAssignedToServiceApply() || $this->hasBeenAssignedToServiceApply()
) { ) {
@ -612,7 +614,8 @@ class IcingaDependency extends IcingaObject implements ExportInterface
$related = parent::getRelatedProperty($key); $related = parent::getRelatedProperty($key);
// handle special case for plain string parent service on Dependency // handle special case for plain string parent service on Dependency
// Apply rules // Apply rules
if ($related === null if (
$related === null
&& $key === 'parent_service' && $key === 'parent_service'
&& ( && (
$this->get('parent_service_by_name') $this->get('parent_service_by_name')

View File

@ -614,7 +614,8 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return true; return true;
} }
if ($this instanceof ObjectWithArguments if (
$this instanceof ObjectWithArguments
&& $this->gotArguments() && $this->gotArguments()
&& $this->arguments()->hasBeenModified() && $this->arguments()->hasBeenModified()
) { ) {
@ -758,8 +759,10 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return $this; return $this;
} }
if ($this instanceof ObjectWithArguments if (
&& substr($key, 0, 10) === 'arguments.') { $this instanceof ObjectWithArguments
&& substr($key, 0, 10) === 'arguments.'
) {
$this->arguments()->set(substr($key, 10), $value); $this->arguments()->set(substr($key, 10), $value);
return $this; return $this;
} }
@ -1764,7 +1767,8 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
$deploymentMode = $config->getDeploymentMode(); $deploymentMode = $config->getDeploymentMode();
if ($deploymentMode === 'active-passive') { if ($deploymentMode === 'active-passive') {
if ($this->getSingleResolvedProperty('zone_id') if (
$this->getSingleResolvedProperty('zone_id')
&& array_key_exists('enable_active_checks', $this->defaultProperties) && array_key_exists('enable_active_checks', $this->defaultProperties)
) { ) {
$passive = clone($this); $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)) && $this->hasRelation($relKey = substr($key, 0, -3))
) { ) {
return $this->renderRelationProperty($relKey, $value); 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)) && $this->hasRelation($relKey = substr($key, 0, -3))
) { ) {
return $this->renderLegacyRelationProperty($relKey, $value); return $this->renderLegacyRelationProperty($relKey, $value);
@ -2401,7 +2407,8 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
$str = ''; $str = '';
// Set notification settings for the object to suppress warnings // 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() && $this->isTemplate()
) { ) {
$str .= c1::renderKeyValue('notification_period', 'notification_none'); $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 // force rendering of check_command when ARG1 is set
if ($this->supportsCustomVars() && array_key_exists('check_command_id', $this->defaultProperties)) { 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 && $this->vars()->get('ARG1') !== null
) { ) {
$command = $this->getResolvedRelated('check_command'); $command = $this->getResolvedRelated('check_command');
@ -2701,7 +2709,8 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
} }
} }
if (PrefetchCache::shouldBeUsed() if (
PrefetchCache::shouldBeUsed()
&& $query === null && $query === null
&& $keyColumn === static::getKeyColumnName() && $keyColumn === static::getKeyColumnName()
) { ) {
@ -3119,7 +3128,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
public function getOnDeleteUrl() public function getOnDeleteUrl()
{ {
$plural= preg_replace('/cys$/', 'cies', strtolower($this->getShortTableName()) . 's'); $plural = preg_replace('/cys$/', 'cies', strtolower($this->getShortTableName()) . 's');
return 'director/' . $plural; return 'director/' . $plural;
} }

View File

@ -342,7 +342,7 @@ class IcingaObjectGroups implements Iterator, Countable, IcingaConfigRenderer
protected function getGroupClass() 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) public static function loadForStoredObject(IcingaObject $object)
@ -380,7 +380,7 @@ class IcingaObjectGroups implements Iterator, Countable, IcingaConfigRenderer
} }
$type = $this->object->getLegacyObjectType(); $type = $this->object->getLegacyObjectType();
return c1::renderKeyValue($type.'groups', c1::renderArray($groups)); return c1::renderKeyValue($type . 'groups', c1::renderArray($groups));
} }
public function __toString() public function __toString()

View File

@ -47,7 +47,8 @@ class IcingaScheduledDowntimeRange extends DbObject
{ {
$hBegin = $mBegin = $hEnd = $mEnd = null; $hBegin = $mBegin = $hEnd = $mEnd = null;
if (sscanf($rangeString, '%2d:%2d-%2d:%2d', $hBegin, $mBegin, $hEnd, $mEnd) === 4) { 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 && $this->timeFromHourMin($hEnd, $mEnd, $now) >= $now
) { ) {
return true; return true;

View File

@ -307,7 +307,8 @@ class IcingaService extends IcingaObject implements ExportInterface
$str = parent::toLegacyConfigString(); $str = parent::toLegacyConfigString();
if (! $this->isDisabled() if (
! $this->isDisabled()
&& $this->get('host_id') && $this->get('host_id')
&& $this->getRelated('host')->isDisabled() && $this->getRelated('host')->isDisabled()
) { ) {
@ -329,7 +330,8 @@ class IcingaService extends IcingaObject implements ExportInterface
} }
$str = parent::toConfigString(); $str = parent::toConfigString();
if (! $this->isDisabled() if (
! $this->isDisabled()
&& $this->get('host_id') && $this->get('host_id')
&& $this->getRelated('host')->isDisabled() && $this->getRelated('host')->isDisabled()
) { ) {
@ -346,7 +348,8 @@ class IcingaService extends IcingaObject implements ExportInterface
*/ */
protected function renderObjectHeader() protected function renderObjectHeader()
{ {
if ($this->isApplyRule() if (
$this->isApplyRule()
&& !$this->hasBeenAssignedToHostTemplate() && !$this->hasBeenAssignedToHostTemplate()
&& $this->get('apply_for') !== null && $this->get('apply_for') !== null
) { ) {
@ -609,7 +612,8 @@ class IcingaService extends IcingaObject implements ExportInterface
{ {
$where = parent::createWhere(); $where = parent::createWhere();
if (! $this->hasBeenLoadedFromDb()) { 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('host_id')
&& null === $this->get('id') && null === $this->get('id')
) { ) {
@ -717,7 +721,8 @@ class IcingaService extends IcingaObject implements ExportInterface
protected function beforeStore() protected function beforeStore()
{ {
parent::beforeStore(); parent::beforeStore();
if ($this->isObject() if (
$this->isObject()
&& $this->get('service_set_id') === null && $this->get('service_set_id') === null
&& $this->get('host_id') === null && $this->get('host_id') === null
) { ) {

View File

@ -47,7 +47,8 @@ class IcingaTimePeriodRange extends DbObject
{ {
$hBegin = $mBegin = $hEnd = $mEnd = null; $hBegin = $mBegin = $hEnd = $mEnd = null;
if (sscanf($rangeString, '%2d:%2d-%2d:%2d', $hBegin, $mBegin, $hEnd, $mEnd) === 4) { 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 && $this->timeFromHourMin($hEnd, $mEnd, $now) >= $now
) { ) {
return true; return true;

View File

@ -27,7 +27,7 @@ class IcingaTimePeriodRanges extends IcingaRanges implements Iterator, Countable
); );
} }
if ($out !== '') { if ($out !== '') {
$out = "\n".$out; $out = "\n" . $out;
} }
return $out; return $out;

View File

@ -45,7 +45,7 @@ class ImportRowModifier extends DbObjectWithSettings implements InstantiatedViaH
$class $class
)); ));
} }
$obj = new $class; $obj = new $class();
$obj->setSettings($this->getSettings()); $obj->setSettings($this->getSettings());
$obj->setPropertyName($this->get('property_name')); $obj->setPropertyName($this->get('property_name'));
$obj->setTargetProperty($this->get('target_property')); $obj->setTargetProperty($this->get('target_property'));

View File

@ -132,7 +132,7 @@ class ImportSource extends DbObjectWithSettings implements ExportInterface
protected static function existsWithNameAndId($name, $id, Db $connection) protected static function existsWithNameAndId($name, $id, Db $connection)
{ {
$db = $connection->getDbAdapter(); $db = $connection->getDbAdapter();
$dummy = new static; $dummy = new static();
$idCol = $dummy->autoincKeyName; $idCol = $dummy->autoincKeyName;
$keyCol = $dummy->keyName; $keyCol = $dummy->keyName;

View File

@ -487,7 +487,7 @@ class SyncRule extends DbObject implements ExportInterface
protected static function existsWithNameAndId($name, $id, Db $connection) protected static function existsWithNameAndId($name, $id, Db $connection)
{ {
$db = $connection->getDbAdapter(); $db = $connection->getDbAdapter();
$dummy = new static; $dummy = new static();
$idCol = $dummy->autoincKeyName; $idCol = $dummy->autoincKeyName;
$keyCol = $dummy->keyName; $keyCol = $dummy->keyName;

View File

@ -4,6 +4,7 @@ namespace Icinga\Module\Director\PropertyModifier;
use Icinga\Exception\InvalidPropertyException; use Icinga\Exception\InvalidPropertyException;
use Icinga\Module\Director\Hook\PropertyModifierHook; use Icinga\Module\Director\Hook\PropertyModifierHook;
use function array_unique; use function array_unique;
use function array_values; use function array_values;
use function is_array; use function is_array;

View File

@ -27,10 +27,10 @@ class PropertyModifierFromAdSid extends PropertyModifierHook
$sidHex = unpack('H*hex', $value); $sidHex = unpack('H*hex', $value);
$sidHex = $sidHex['hex']; $sidHex = $sidHex['hex'];
$subAuths = implode('-', unpack('H2/H2/n/N/V*', $sid)); $subAuths = implode('-', unpack('H2/H2/n/N/V*', $sid));
$revLevel = hexdec(substr($sidHex, 0, 2)); $revLevel = hexdec(substr($sidHex, 0, 2));
$authIdent = hexdec(substr($sidHex, 4, 12)); $authIdent = hexdec(substr($sidHex, 4, 12));
return sprintf('S-%s-%s-%s', $revLevel, $authIdent, $subAuths); return sprintf('S-%s-%s-%s', $revLevel, $authIdent, $subAuths);
} }
} }

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Director\PropertyModifier; namespace Icinga\Module\Director\PropertyModifier;
use Icinga\Module\Director\Hook\PropertyModifierHook; use Icinga\Module\Director\Hook\PropertyModifierHook;
use function iconv; use function iconv;
class PropertyModifierFromLatin1 extends PropertyModifierHook class PropertyModifierFromLatin1 extends PropertyModifierHook

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Director\PropertyModifier; namespace Icinga\Module\Director\PropertyModifier;
use Icinga\Module\Director\Hook\PropertyModifierHook; use Icinga\Module\Director\Hook\PropertyModifierHook;
use function ipl\Stdlib\get_php_type; use function ipl\Stdlib\get_php_type;
class PropertyModifierNegateBoolean extends PropertyModifierHook class PropertyModifierNegateBoolean extends PropertyModifierHook

View File

@ -8,7 +8,6 @@ use Icinga\Module\Director\Web\Form\QuickForm;
class PropertyModifierParseURL extends PropertyModifierHook class PropertyModifierParseURL extends PropertyModifierHook
{ {
/** /**
* Array with possible components that can be returned from URL. * Array with possible components that can be returned from URL.
*/ */

View File

@ -7,12 +7,11 @@ use Icinga\Module\Director\Web\Form\QuickForm;
class PropertyModifierReplaceNull extends PropertyModifierHook class PropertyModifierReplaceNull extends PropertyModifierHook
{ {
public function getName() public function getName()
{ {
return 'Replace null value with String'; return 'Replace null value with String';
} }
public static function addSettingsFormFields(QuickForm $form) public static function addSettingsFormFields(QuickForm $form)
{ {
$form->addElement('text', 'string', [ $form->addElement('text', 'string', [

View File

@ -6,5 +6,4 @@ use Icinga\Module\Icingadb\Hook\IcingadbSupportHook;
class IcingadbSupport extends IcingadbSupportHook class IcingadbSupport extends IcingadbSupportHook
{ {
} }

View File

@ -80,7 +80,8 @@ class HostServiceBlacklist
public function getPreLoadedMappingsForService(IcingaService $service) public function getPreLoadedMappingsForService(IcingaService $service)
{ {
if ($this->mappings !== null if (
$this->mappings !== null
&& array_key_exists($service->get('id'), $this->mappings) && array_key_exists($service->get('id'), $this->mappings)
) { ) {
return $this->mappings[$service->get('id')]; return $this->mappings[$service->get('id')];

View File

@ -137,7 +137,8 @@ class TemplateTree
public function getAncestorsFor(IcingaObject $object) public function getAncestorsFor(IcingaObject $object)
{ {
if ($object->hasBeenModified() if (
$object->hasBeenModified()
&& $object->gotImports() && $object->gotImports()
&& $object->imports()->hasBeenModified() && $object->imports()->hasBeenModified()
) { ) {

View File

@ -14,9 +14,9 @@ use Icinga\Module\Director\Objects\SyncRule;
abstract class SyncTest extends BaseTestCase abstract class SyncTest extends BaseTestCase
{ {
protected $objectType; protected $objectType;
protected $keyColumn; protected $keyColumn;
/** @var ImportSource */ /** @var ImportSource */
protected $source; protected $source;

View File

@ -59,7 +59,7 @@ class TestSuiteStyle extends TestSuite
`$cmd`; `$cmd`;
echo $cmd . "\n"; echo $cmd . "\n";
echo $out ."\n"; echo $out . "\n";
echo file_get_contents($out); echo file_get_contents($out);
unlink($out); unlink($out);
} }

View File

@ -50,7 +50,8 @@ abstract class ActionController extends Controller implements ControlsAndContent
*/ */
public function init() public function init()
{ {
if (! $this->getRequest()->isApiRequest() if (
! $this->getRequest()->isApiRequest()
&& $this->Config()->get('frontend', 'disabled', 'no') === 'yes' && $this->Config()->get('frontend', 'disabled', 'no') === 'yes'
) { ) {
throw new NotFoundError('Not found'); throw new NotFoundError('Not found');

View File

@ -174,7 +174,8 @@ abstract class ObjectController extends ActionController
$this->tabs()->activate('modify'); $this->tabs()->activate('modify');
$this->addObjectTitle(); $this->addObjectTitle();
// Hint: Service Sets are 'templates' (as long as not being assigned to a host // 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() && $object->isTemplate()
&& $this->showNotInBranch($this->translate('Modifying Templates')) && $this->showNotInBranch($this->translate('Modifying Templates'))
) { ) {
@ -460,7 +461,8 @@ abstract class ObjectController extends ActionController
protected function redirectToPreviewForExternals() protected function redirectToPreviewForExternals()
{ {
if ($this->object if (
$this->object
&& $this->object->isExternal() && $this->object->isExternal()
&& ! in_array($this->object->getShortTableName(), $this->allowedExternals) && ! in_array($this->object->getShortTableName(), $this->allowedExternals)
) { ) {
@ -566,7 +568,8 @@ abstract class ObjectController extends ActionController
} }
if ($showHint) { if ($showHint) {
$hasPreferredBranch = $this->hasPreferredBranch(); $hasPreferredBranch = $this->hasPreferredBranch();
if (($hasPreferredBranch || $branch->isBranch()) if (
($hasPreferredBranch || $branch->isBranch())
&& $object->isObject() && $object->isObject()
&& ! $this->getRequest()->isApiRequest() && ! $this->getRequest()->isApiRequest()
) { ) {

View File

@ -73,7 +73,8 @@ abstract class ObjectsController extends ActionController
{ {
$request = $this->getRequest(); $request = $this->getRequest();
$table = $this->getTable(); $table = $this->getTable();
if ($request->getControllerName() === 'services' if (
$request->getControllerName() === 'services'
&& $host = $this->params->get('host') && $host = $this->params->get('host')
) { ) {
$host = IcingaHost::load($host, $this->db()); $host = IcingaHost::load($host, $this->db());

View File

@ -17,7 +17,7 @@ class SimpleNote extends FormElement
*/ */
protected $_ignore = true; protected $_ignore = true;
// @codingStandardsIgnoreEnd // @codingStandardsIgnoreEnd
public function isValid($value, $context = null) public function isValid($value, $context = null)
{ {
return true; return true;

View File

@ -37,7 +37,8 @@ class StoredPassword extends ZfText
public function setValue($value) 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['_sent'] === 'y'
) { ) {
$value = $sentValue = $value['_value']; $value = $sentValue = $value['_value'];

View File

@ -568,7 +568,7 @@ class IcingaObjectFieldLoader
$id = $r->object_id; $id = $r->object_id;
unset($r->object_id); unset($r->object_id);
if (! array_key_exists($id, $result)) { if (! array_key_exists($id, $result)) {
$result[$id] = new stdClass; $result[$id] = new stdClass();
} }
$result[$id]->{$r->varname} = DirectorDatafield::fromDbRow( $result[$id]->{$r->varname} = DirectorDatafield::fromDbRow(

View File

@ -47,7 +47,7 @@ class IconHelper
public static function instance() public static function instance()
{ {
if (self::$instance === null) { if (self::$instance === null) {
self::$instance = new static; self::$instance = new static();
} }
return self::$instance; return self::$instance;

View File

@ -78,7 +78,7 @@ abstract class QuickBaseForm extends Zend_Form implements ValidHtml
$this->setDefault($name, $value); $this->setDefault($name, $value);
$el->setValue($value); $el->setValue($value);
} }
return $this; return $this;
} }

View File

@ -80,7 +80,7 @@ class ActivityLogTable extends IntlZfQueryBasedTable
{ {
$this->currentRow = $row; $this->currentRow = $row;
$this->splitByDay($row->ts_change_time); $this->splitByDay($row->ts_change_time);
$action = 'action-' . $row->action. ' '; $action = 'action-' . $row->action . ' ';
if ($row->id > $this->lastDeployedId) { if ($row->id > $this->lastDeployedId) {
$action .= 'undeployed'; $action .= 'undeployed';
} else { } else {

View File

@ -54,7 +54,8 @@ class DeploymentLogTable extends IntlZfQueryBasedTable
$classes = ['notsent']; $classes = ['notsent'];
} }
if ($this->activeStageName !== null if (
$this->activeStageName !== null
&& $row->stage_name === $this->activeStageName && $row->stage_name === $this->activeStageName
) { ) {
$classes[] = 'running'; $classes[] = 'running';

View File

@ -124,7 +124,7 @@ class IcingaServiceSetServiceTable extends ZfQueryBasedTable
$url = 'director/host/servicesetservice'; $url = 'director/host/servicesetservice';
} else { } else {
if (is_resource($row->uuid)) { if (is_resource($row->uuid)) {
$row->uuid =stream_get_contents($row->uuid); $row->uuid = stream_get_contents($row->uuid);
} }
$params = [ $params = [

View File

@ -43,9 +43,9 @@ abstract class IntlZfQueryBasedTable extends ZfQueryBasedTable
$timeFormatter = $this->getDateFormatter(); $timeFormatter = $this->getDateFormatter();
$timeFormatter->setPattern( $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)); return $timeFormatter->format((new DateTime())->setTimestamp($timeStamp));
} }
} }

View File

@ -82,7 +82,7 @@ class PropertymodifierTable extends ZfQueryBasedTable
$class = $row->provider_class; $class = $row->provider_class;
try { try {
/** @var ImportSourceHook $hook */ /** @var ImportSourceHook $hook */
$hook = new $class; $hook = new $class();
$caption .= ': ' . $hook->getName(); $caption .= ': ' . $hook->getName();
} catch (Exception $e) { } catch (Exception $e) {
$caption = $this->createErrorCaption($caption, $e); $caption = $this->createErrorCaption($caption, $e);

View File

@ -7,7 +7,6 @@ use Ramsey\Uuid\UuidInterface;
trait TableWithBranchSupport trait TableWithBranchSupport
{ {
/** @var UuidInterface|null */ /** @var UuidInterface|null */
protected $branchUuid; protected $branchUuid;

View File

@ -102,7 +102,8 @@ class ObjectTabs extends Tabs
} }
// TODO: remove table check once we resolve all group types // TODO: remove table check once we resolve all group types
if ($object->isGroup() && if (
$object->isGroup() &&
($object->getShortTableName() === 'hostgroup' || $object->getShortTableName() === 'servicegroup') ($object->getShortTableName() === 'hostgroup' || $object->getShortTableName() === 'servicegroup')
) { ) {
$this->add('membership', [ $this->add('membership', [
@ -120,7 +121,8 @@ class ObjectTabs extends Tabs
]); ]);
} }
if ($object->getShortTableName() === 'endpoint' if (
$object->getShortTableName() === 'endpoint'
&& $object->get('apiuser_id') && $object->get('apiuser_id')
) { ) {
$this->add('inspect', [ $this->add('inspect', [

View File

@ -37,14 +37,16 @@ class ObjectsTabs extends Tabs
]); ]);
} }
if ($auth->hasPermission(Permission::ADMIN) if (
$auth->hasPermission(Permission::ADMIN)
|| ( || (
$object->getShortTableName() === 'notification' $object->getShortTableName() === 'notification'
&& $auth->hasPermission(Permission::NOTIFICATIONS) && $auth->hasPermission(Permission::NOTIFICATIONS)
) || ( ) || (
$object->getShortTableName() === 'scheduled_downtime' $object->getShortTableName() === 'scheduled_downtime'
&& $auth->hasPermission(Permission::SCHEDULED_DOWNTIMES) && $auth->hasPermission(Permission::SCHEDULED_DOWNTIMES)
)) { )
) {
if ($object->supportsApplyRules()) { if ($object->supportsApplyRules()) {
$this->add('applyrules', [ $this->add('applyrules', [
'url' => sprintf('director/%s/applyrules', $plType), 'url' => sprintf('director/%s/applyrules', $plType),

View File

@ -73,7 +73,7 @@ class TemplateTreeRenderer extends BaseHtmlElement
$tree['name'], $tree['name'],
"director/{$type}template/usage", "director/{$type}template/usage",
array('name' => $tree['name']), array('name' => $tree['name']),
array('class' => 'icon-' .$type) array('class' => 'icon-' . $type)
)); ));
} }

Some files were not shown because too many files have changed in this diff Show More