Align coding style to comply with latest PSR

This commit is contained in:
Eric Lippmann 2025-12-12 12:12:15 +01:00
parent 079654b59c
commit c85b9d98fe
32 changed files with 85 additions and 64 deletions

View file

@ -59,7 +59,8 @@ class CleanupCommand extends Command
continue;
}
if (Module::exists('icingadb')
if (
Module::exists('icingadb')
&& (! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
) {
IcingaDbState::apply($bp);

View file

@ -136,7 +136,8 @@ class ProcessCommand extends Command
try {
/** @var BpNode $node */
$node = $bp->getNode($nodeName);
if (Module::exists('icingadb')
if (
Module::exists('icingadb')
&& (! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
) {
IcingaDbState::apply($bp);

View file

@ -95,7 +95,8 @@ class NodeController extends Controller
continue;
}
if (Module::exists('icingadb') &&
if (
Module::exists('icingadb') &&
(! $config->getBackendName() && IcingadbSupport::useIcingaDbAsBackend())
) {
IcingaDbState::apply($config);

View file

@ -94,7 +94,8 @@ class ProcessController extends Controller
$bp = $this->loadModifiedBpConfig();
$node = $this->getNode($bp);
if (Module::exists('icingadb') &&
if (
Module::exists('icingadb') &&
(! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
) {
IcingaDbState::apply($bp);
@ -704,7 +705,7 @@ class ProcessController extends Controller
$tabs = $this->tabs()->add('config', array(
'label' => $this->translate('Process Configuration'),
'url' =>Url::fromPath('businessprocess/process/config', $params)
'url' => Url::fromPath('businessprocess/process/config', $params)
));
if ($this->params->get('showDiff')) {
@ -713,7 +714,7 @@ class ProcessController extends Controller
$tabs->add('source', array(
'label' => $this->translate('Source'),
'url' =>Url::fromPath('businessprocess/process/source', $params)
'url' => Url::fromPath('businessprocess/process/source', $params)
));
return $tabs;

View file

@ -56,7 +56,7 @@ class ServiceController extends Controller
} else {
$hostName = $this->params->get('host');
$serviceName = $this->params->get('service');
$query = $this->backend->select()
->from('servicestatus', array('service_description'))
->where('host_name', $hostName)

View file

@ -84,7 +84,8 @@ class SuggestionsController extends Controller
$search = "@$config:$search";
}
if (in_array($search, $suggestions->getExcludeTerms(), true)
if (
in_array($search, $suggestions->getExcludeTerms(), true)
|| isset($ignoreList[$search])
|| ($forParent
? $forParent->hasChild($search)
@ -94,7 +95,8 @@ class SuggestionsController extends Controller
continue;
}
if ($suggestions->matchSearch($bpNode->getName())
if (
$suggestions->matchSearch($bpNode->getName())
|| (! $bpNode->hasAlias() || $suggestions->matchSearch($bpNode->getAlias()))
|| $bpNode->getName() === $suggestions->getOriginalSearchValue()
|| $bpNode->getAlias() === $suggestions->getOriginalSearchValue()

View file

@ -204,8 +204,10 @@ class BpConfigForm extends BpConfigBaseForm
}
$meta = $config->getMetadata();
foreach ($this->getValues() as $key => $value) {
if (! in_array($key, ['Title', 'Description', 'Backend'], true)
&& ($value === null || $value === '')) {
if (
! in_array($key, ['Title', 'Description', 'Backend'], true)
&& ($value === null || $value === '')
) {
continue;
}

View file

@ -10,7 +10,8 @@ class Zend_View_Helper_RenderStateBadges extends Zend_View_Helper_Abstract // ph
$html = '';
foreach ($summary as $state => $cnt) {
if ($cnt === 0
if (
$cnt === 0
|| $state === 'OK'
|| $state === 'UP'
) {

View file

@ -15,9 +15,9 @@ use ipl\Sql\Connection as IcingaDbConnection;
class BpConfig
{
const SOFT_STATE = 0;
public const SOFT_STATE = 0;
const HARD_STATE = 1;
public const HARD_STATE = 1;
/**
* Name of the configured monitoring backend
@ -295,8 +295,10 @@ class BpConfig
public function getBackend()
{
if ($this->backend === null) {
if (Module::exists('icingadb')
&& (! $this->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())) {
if (
Module::exists('icingadb')
&& (! $this->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
) {
$this->backend = IcingaDbObject::fetchDb();
} else {
$this->backend = MonitoringBackend::instance(

View file

@ -9,11 +9,11 @@ use ipl\Web\Widget\Icon;
class BpNode extends Node
{
const OP_AND = '&';
const OP_OR = '|';
const OP_XOR = '^';
const OP_NOT = '!';
const OP_DEGRADED = '%';
public const OP_AND = '&';
public const OP_OR = '|';
public const OP_XOR = '^';
public const OP_NOT = '!';
public const OP_DEGRADED = '%';
protected $operator = '&';
@ -261,7 +261,7 @@ class BpNode extends Node
if ($child instanceof MonitoredNode) {
$empty = false;
break;
} elseif (!$child->isEmpty()) {
} elseif (! $child->isEmpty()) {
$empty = false;
}
}
@ -561,7 +561,7 @@ class BpNode extends Node
public function hasChildren($filter = null)
{
$childNames = $this->getChildNames();
return !empty($childNames);
return ! empty($childNames);
}
public function getChildNames()

View file

@ -1,4 +1,5 @@
<?php
// Icinga Business Process Modelling | (c) 2023 Icinga GmbH | GPLv2
namespace Icinga\Module\Businessprocess\Common;

View file

@ -80,7 +80,7 @@ class IcingaDbObject
public static function applyIcingaDbRestrictions($query)
{
$object = new self;
$object = new self();
$object->applyRestrictions($query);
return $object;
@ -88,7 +88,7 @@ class IcingaDbObject
public static function fetchDb()
{
$object = new self;
$object = new self();
return $object->getDb();
}
}

View file

@ -78,7 +78,7 @@ class NodeCreateAction extends NodeAction
}
$parent = $this->getParentName();
if ($parent !== null && !$config->hasBpNode($parent)) {
if ($parent !== null && ! $config->hasBpNode($parent)) {
$this->error('Parent process "%s" missing', $parent);
}

View file

@ -45,7 +45,7 @@ class NodeRemoveAction extends NodeAction
$name = $this->getNodeName();
$parent = $this->getParentName();
if ($parent === null) {
if (!$config->hasNode($name)) {
if (! $config->hasNode($name)) {
$this->error('Toplevel process "%s" not found', $name);
}
} else {

View file

@ -35,7 +35,8 @@ trait CustomVarJoinTemplateOverride
$this->customVars[strtolower($customvar)] = $alias;
if ($type === 'host') {
if ($this instanceof ServicecommentQuery
if (
$this instanceof ServicecommentQuery
|| $this instanceof ServicedowntimeQuery
|| $this instanceof ServicecommenthistoryQuery
|| $this instanceof ServicedowntimestarthistoryQuery

View file

@ -8,21 +8,21 @@ use ipl\Web\Widget\Icon;
abstract class Node
{
const FLAG_DOWNTIME = 1;
const FLAG_ACK = 2;
const FLAG_MISSING = 4;
const FLAG_NONE = 8;
const SHIFT_FLAGS = 4;
public const FLAG_DOWNTIME = 1;
public const FLAG_ACK = 2;
public const FLAG_MISSING = 4;
public const FLAG_NONE = 8;
public const SHIFT_FLAGS = 4;
const ICINGA_OK = 0;
const ICINGA_WARNING = 1;
const ICINGA_CRITICAL = 2;
const ICINGA_UNKNOWN = 3;
const ICINGA_UP = 0;
const ICINGA_DOWN = 1;
const ICINGA_UNREACHABLE = 2;
const ICINGA_PENDING = 99;
const NODE_EMPTY = 128;
public const ICINGA_OK = 0;
public const ICINGA_WARNING = 1;
public const ICINGA_CRITICAL = 2;
public const ICINGA_UNKNOWN = 3;
public const ICINGA_UP = 0;
public const ICINGA_DOWN = 1;
public const ICINGA_UNREACHABLE = 2;
public const ICINGA_PENDING = 99;
public const NODE_EMPTY = 128;
/** @var bool Whether to treat acknowledged hosts/services always as UP/OK */
protected static $ackIsOk = false;

View file

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

View file

@ -64,7 +64,8 @@ class ServiceDetailExtension extends ServiceDetailExtensionHook
public function getHtmlForObject(Service $service): ValidHtml
{
if (! isset($this->storage)
if (
! isset($this->storage)
|| $service->checkcommand_name !== $this->commandName
) {
return HtmlString::create('');

View file

@ -69,7 +69,8 @@ class DetailviewExtension extends DetailviewExtensionHook
*/
public function getHtmlForObject(MonitoredObject $object)
{
if (! isset($this->storage)
if (
! isset($this->storage)
|| ! $object instanceof Service
|| $object->check_command !== $this->commandName
) {

View file

@ -25,7 +25,7 @@ class Breadcrumb extends BaseHtmlElement
public static function create(Renderer $renderer)
{
$bp = $renderer->getBusinessProcess();
$breadcrumb = new static;
$breadcrumb = new static();
$bpUrl = $renderer->getBaseUrl();
if ($bpUrl->getParam('action') === 'delete') {
$bpUrl->remove('action');

View file

@ -191,7 +191,7 @@ abstract class Renderer extends HtmlDocument
$this->createBadge($summary, 'PENDING')
]);
if (!empty($elements)) {
if (! empty($elements)) {
$container = Html::tag('ul', ['class' => 'state-badges']);
$container->add($itemCount);
foreach ($elements as $element) {

View file

@ -107,7 +107,8 @@ class NodeTile extends BaseHtmlElement
$this->add(new Link($node->getAlias(), $this->getMainNodeUrl($node)->getAbsoluteUrl()));
}
if ($this->renderer->rendersSubNode()
if (
$this->renderer->rendersSubNode()
&& $this->renderer->getParentNode()->getChildState($node) !== $node->getState()
) {
$this->add(
@ -122,7 +123,7 @@ class NodeTile extends BaseHtmlElement
);
}
if ($node instanceof BpNode && !$renderer->isBreadcrumb()) {
if ($node instanceof BpNode && ! $renderer->isBreadcrumb()) {
$this->add($renderer->renderStateBadges($node->getStateSummary(), $node->countChildren()));
}
@ -144,7 +145,8 @@ class NodeTile extends BaseHtmlElement
$url = $this->renderer->getBaseUrl();
$p = $url->getParams();
if ($node instanceof ImportedNode
if (
$node instanceof ImportedNode
&& $this->renderer->getBusinessProcess()->getName() === $node->getBpConfig()->getName()
) {
$p->set('node', $node->getNodeName());
@ -304,7 +306,8 @@ class NodeTile extends BaseHtmlElement
));
}
if ($this->renderer->getBusinessProcess()->getMetadata()->canModify()
if (
$this->renderer->getBusinessProcess()->getMetadata()->canModify()
&& $this->node->getBpConfig()->getName() === $this->renderer->getBusinessProcess()->getName()
&& $this->node->getName() !== '__unbound__'
) {

View file

@ -18,7 +18,7 @@ use ipl\Web\Widget\StateBall;
class TreeRenderer extends Renderer
{
const NEW_COLLAPSIBLE_IMPLEMENTATION_SINCE = '2.11.2';
public const NEW_COLLAPSIBLE_IMPLEMENTATION_SINCE = '2.11.2';
public function assemble()
{
@ -229,7 +229,7 @@ class TreeRenderer extends Renderer
}
$differentConfig = $node->getBpConfig()->getName() !== $this->getBusinessProcess()->getName();
if (! $this->isLocked() && !$differentConfig) {
if (! $this->isLocked() && ! $differentConfig) {
$summary->add($this->getActionIcons($bp, $node));
} elseif ($differentConfig) {
$summary->add($this->actionIcon(

View file

@ -7,7 +7,7 @@ use Icinga\Web\Session\SessionNamespace;
class Simulation
{
const DEFAULT_SESSION_KEY = 'bp-simulations';
public const DEFAULT_SESSION_KEY = 'bp-simulations';
/**
* @var SessionNamespace

View file

@ -109,7 +109,8 @@ class Dashboard extends BaseHtmlElement
continue;
}
if (Module::exists('icingadb') &&
if (
Module::exists('icingadb') &&
(! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
) {
IcingaDbState::apply($bp);

View file

@ -66,7 +66,8 @@ class DashboardFullscreen extends BaseHtmlElement
continue;
}
if (Module::exists('icingadb') &&
if (
Module::exists('icingadb') &&
(! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
) {
IcingaDbState::apply($bp);

View file

@ -19,7 +19,7 @@ class CsrfToken
list($seed, $token) = explode('|', $token);
if (!is_numeric($seed)) {
if (! is_numeric($seed)) {
return false;
}

View file

@ -4,5 +4,4 @@ namespace Icinga\Module\Businessprocess\Web\Form\Element;
class Checkbox extends \Icinga\Web\Form\Element\Checkbox
{
}

View file

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

View file

@ -16,9 +16,9 @@ use Exception;
*/
abstract class QuickForm extends QuickBaseForm
{
const ID = '__FORM_NAME';
public const ID = '__FORM_NAME';
const CSRF = '__FORM_CSRF';
public const CSRF = '__FORM_CSRF';
/**
* The name of this form

View file

@ -48,7 +48,8 @@ class ProcessProblemsBadge extends BadgeNavigationItemRenderer
$bp = $storage->loadProcess($this->getBpConfigName());
foreach ($bp->getRootNodes() as $rootNode) {
$nodeState = $rootNode->getState();
if (! $rootNode->isEmpty() &&
if (
! $rootNode->isEmpty() &&
! in_array($nodeState, [Node::ICINGA_OK, Node::ICINGA_PENDING], true)
) {
if ($nodeState === $state) {

View file

@ -32,7 +32,8 @@ class ProcessesProblemsBadge extends BadgeNavigationItemRenderer
foreach ($storage->listProcessNames() as $processName) {
$bp = $storage->loadProcess($processName);
if (Module::exists('icingadb') &&
if (
Module::exists('icingadb') &&
(! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
) {
IcingaDbState::apply($bp);
@ -42,7 +43,8 @@ class ProcessesProblemsBadge extends BadgeNavigationItemRenderer
foreach ($bp->getRootNodes() as $rootNode) {
$nodeState = $rootNode->getState();
if (! $rootNode->isEmpty() &&
if (
! $rootNode->isEmpty() &&
! in_array($nodeState, [Node::ICINGA_OK, Node::ICINGA_PENDING], true)
) {
if ($nodeState === $state) {