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; continue;
} }
if (Module::exists('icingadb') if (
Module::exists('icingadb')
&& (! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend()) && (! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
) { ) {
IcingaDbState::apply($bp); IcingaDbState::apply($bp);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -107,7 +107,8 @@ class NodeTile extends BaseHtmlElement
$this->add(new Link($node->getAlias(), $this->getMainNodeUrl($node)->getAbsoluteUrl())); $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->renderer->getParentNode()->getChildState($node) !== $node->getState()
) { ) {
$this->add( $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())); $this->add($renderer->renderStateBadges($node->getStateSummary(), $node->countChildren()));
} }
@ -144,7 +145,8 @@ class NodeTile extends BaseHtmlElement
$url = $this->renderer->getBaseUrl(); $url = $this->renderer->getBaseUrl();
$p = $url->getParams(); $p = $url->getParams();
if ($node instanceof ImportedNode if (
$node instanceof ImportedNode
&& $this->renderer->getBusinessProcess()->getName() === $node->getBpConfig()->getName() && $this->renderer->getBusinessProcess()->getName() === $node->getBpConfig()->getName()
) { ) {
$p->set('node', $node->getNodeName()); $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->getBpConfig()->getName() === $this->renderer->getBusinessProcess()->getName()
&& $this->node->getName() !== '__unbound__' && $this->node->getName() !== '__unbound__'
) { ) {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -4,5 +4,4 @@ namespace Icinga\Module\Businessprocess\Web\Form\Element;
class Checkbox extends \Icinga\Web\Form\Element\Checkbox 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); $this->setDefault($name, $value);
$el->setValue($value); $el->setValue($value);
} }
return $this; return $this;
} }

View file

@ -16,9 +16,9 @@ use Exception;
*/ */
abstract class QuickForm extends QuickBaseForm 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 * The name of this form

View file

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

View file

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