From 9f58dcf8d9b85f9fdfd153518d3375caefc9ceb0 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 17 Jan 2024 13:25:54 +0100 Subject: [PATCH 01/10] phpstan: Strict check `function/class` name-case and fix violations --- application/controllers/ImportsourcesController.php | 2 +- application/controllers/JobsController.php | 2 +- application/controllers/SchemaController.php | 2 +- application/controllers/SyncruleController.php | 4 ++-- application/controllers/SyncrulesController.php | 2 +- application/forms/IcingaTemplateChoiceForm.php | 4 ++-- library/Director/Import/ImportSourceLdap.php | 2 +- library/Director/Resolver/IcingaObjectResolver.php | 2 +- library/Director/Web/Form/DirectorForm.php | 2 +- phpstan.neon | 4 ++-- 10 files changed, 13 insertions(+), 13 deletions(-) diff --git a/application/controllers/ImportsourcesController.php b/application/controllers/ImportsourcesController.php index 42872927..f0021c50 100644 --- a/application/controllers/ImportsourcesController.php +++ b/application/controllers/ImportsourcesController.php @@ -30,7 +30,7 @@ class ImportsourcesController extends ActionController } $this->addTitle($this->translate('Import source')) - ->setAutoRefreshInterval(10) + ->setAutorefreshInterval(10) ->addAddLink( $this->translate('Add a new Import Source'), 'director/importsource/add' diff --git a/application/controllers/JobsController.php b/application/controllers/JobsController.php index 11e86ed2..04c6d342 100644 --- a/application/controllers/JobsController.php +++ b/application/controllers/JobsController.php @@ -11,7 +11,7 @@ class JobsController extends ActionController public function indexAction() { $this->addTitle($this->translate('Jobs')) - ->setAutoRefreshInterval(10) + ->setAutorefreshInterval(10) ->addAddLink($this->translate('Add a new Job'), 'director/job/add') ->tabs(new ImportTabs())->activate('jobs'); diff --git a/application/controllers/SchemaController.php b/application/controllers/SchemaController.php index b0ca24e4..961b7b1c 100644 --- a/application/controllers/SchemaController.php +++ b/application/controllers/SchemaController.php @@ -62,7 +62,7 @@ class SchemaController extends ActionController return file_get_contents( sprintf( '%s/schema/%s.sql', - $this->Module()->getBasedir(), + $this->Module()->getBaseDir(), $type ) ); diff --git a/application/controllers/SyncruleController.php b/application/controllers/SyncruleController.php index a19da036..e575ad8e 100644 --- a/application/controllers/SyncruleController.php +++ b/application/controllers/SyncruleController.php @@ -48,7 +48,7 @@ class SyncruleController extends ActionController */ public function indexAction() { - $this->setAutoRefreshInterval(10); + $this->setAutorefreshInterval(10); $rule = $this->requireSyncRule(); $this->tabs(new SyncRuleTabs($rule))->activate('show'); $ruleName = $rule->get('rule_name'); @@ -642,7 +642,7 @@ class SyncruleController extends ActionController */ public function historyAction() { - $this->setAutoRefreshInterval(30); + $this->setAutorefreshInterval(30); $rule = $this->requireSyncRule(); $this->tabs(new SyncRuleTabs($rule))->activate('history'); $this->addTitle($this->translate('Sync history') . ': ' . $rule->get('rule_name')); diff --git a/application/controllers/SyncrulesController.php b/application/controllers/SyncrulesController.php index 1829ebe3..1c84ecf4 100644 --- a/application/controllers/SyncrulesController.php +++ b/application/controllers/SyncrulesController.php @@ -23,7 +23,7 @@ class SyncrulesController extends ActionController } $this->addTitle($this->translate('Sync rule')) - ->setAutoRefreshInterval(10) + ->setAutorefreshInterval(10) ->addAddLink( $this->translate('Add a new Sync Rule'), 'director/syncrule/add' diff --git a/application/forms/IcingaTemplateChoiceForm.php b/application/forms/IcingaTemplateChoiceForm.php index 31fe6102..27af5d22 100644 --- a/application/forms/IcingaTemplateChoiceForm.php +++ b/application/forms/IcingaTemplateChoiceForm.php @@ -19,7 +19,7 @@ class IcingaTemplateChoiceForm extends DirectorObjectForm { if ($name !== null) { /** @var IcingaTemplateChoice $class - cheating IDE */ - $class = $this->getObjectClassName(); + $class = $this->getObjectClassname(); $this->setObject($class::load($name, $this->getDb())); } @@ -133,7 +133,7 @@ class IcingaTemplateChoiceForm extends DirectorObjectForm /** @var IcingaTemplateChoice $object */ $object = $this->object(); $this->setSuccessUrl( - 'director/templatechoice/' . $object->getObjectshortTableName(), + 'director/templatechoice/' . $object->getObjectShortTableName(), $object->getUrlParams() ); } diff --git a/library/Director/Import/ImportSourceLdap.php b/library/Director/Import/ImportSourceLdap.php index 45185655..559669dd 100644 --- a/library/Director/Import/ImportSourceLdap.php +++ b/library/Director/Import/ImportSourceLdap.php @@ -45,7 +45,7 @@ class ImportSourceLdap extends ImportSourceHook public static function addSettingsFormFields(QuickForm $form) { - Util::addLDAPResourceFormElement($form, 'resource'); + Util::addLdapResourceFormElement($form, 'resource'); $form->addElement('text', 'base', array( 'label' => $form->translate('LDAP Search Base'), 'description' => $form->translate( diff --git a/library/Director/Resolver/IcingaObjectResolver.php b/library/Director/Resolver/IcingaObjectResolver.php index 579e9db0..c7514763 100644 --- a/library/Director/Resolver/IcingaObjectResolver.php +++ b/library/Director/Resolver/IcingaObjectResolver.php @@ -176,7 +176,7 @@ class IcingaObjectResolver $object->groups = $groups; } - $templates = $this->getTemplateNamesById($id); + $templates = $this->getTemplateNamesByID($id); if (! empty($templates)) { $object->templates = \array_reverse($templates); } diff --git a/library/Director/Web/Form/DirectorForm.php b/library/Director/Web/Form/DirectorForm.php index 145be5ba..36c05777 100644 --- a/library/Director/Web/Form/DirectorForm.php +++ b/library/Director/Web/Form/DirectorForm.php @@ -34,7 +34,7 @@ abstract class DirectorForm extends QuickForm public static function load() { return new static([ - 'icingaModule' => Icinga::App()->getModuleManager()->getModule('director') + 'icingaModule' => Icinga::app()->getModuleManager()->getModule('director') ]); } diff --git a/phpstan.neon b/phpstan.neon index d4fb713f..b3f86b05 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,8 +4,8 @@ includes: parameters: level: 2 - checkFunctionNameCase: false - checkInternalClassCaseSensitivity: false + checkFunctionNameCase: true + checkInternalClassCaseSensitivity: true treatPhpDocTypesAsCertain: false paths: From deddcde0ddf97bc35647066387265a31bbed22d7 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 17 Jan 2024 13:32:36 +0100 Subject: [PATCH 02/10] phpstan: Relax unmatched ignore errors for certain messages --- phpstan.neon | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index b3f86b05..b61aa70a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -13,8 +13,11 @@ parameters: - library/Director ignoreErrors: - - '#Unsafe usage of new static\(\)#' - - '#. but return statement is missing#' + - + messages: + - '#Unsafe usage of new static\(\)#' + - '#. but return statement is missing#' + reportUnmatched: false scanDirectories: - /icingaweb2 From bb8076a09d89c50ade5fbbc03b9fa471853bf6b6 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 17 Jan 2024 14:59:56 +0100 Subject: [PATCH 03/10] `var_export()` expects #param 2 to be bool --- application/controllers/SelfServiceController.php | 2 +- library/Director/Core/RestApiResponse.php | 2 +- library/Director/CustomVariable/CustomVariable.php | 2 +- library/Director/CustomVariable/CustomVariableBoolean.php | 2 +- library/Director/CustomVariable/CustomVariableNull.php | 2 +- library/Director/CustomVariable/CustomVariableNumber.php | 2 +- library/Director/Data/Db/DbDataFormatter.php | 2 +- library/Director/Data/Db/DbObject.php | 2 +- library/Director/Data/PropertyMangler.php | 4 ++-- library/Director/Db/Branch/Branch.php | 2 +- library/Director/Db/IcingaObjectFilterHelper.php | 2 +- library/Director/DirectorObject/Automation/BasketSnapshot.php | 2 +- library/Director/IcingaConfig/IcingaConfigHelper.php | 2 +- library/Director/Import/SyncUtils.php | 2 +- library/Director/Objects/DirectorDatalistEntry.php | 2 +- library/Director/Objects/IcingaObjectGroups.php | 2 +- library/Director/Objects/IcingaObjectMultiRelations.php | 2 +- library/Director/Objects/IcingaRelatedObject.php | 2 +- library/Director/Objects/IcingaTemplateChoice.php | 2 +- library/Director/PlainObjectRenderer.php | 2 +- .../Director/PropertyModifier/PropertyModifierArrayFilter.php | 2 +- .../PropertyModifier/PropertyModifierExtractFromDN.php | 2 +- .../PropertyModifier/PropertyModifierRejectOrSelect.php | 2 +- library/Director/RestApi/RestApiClient.php | 2 +- library/Director/Web/Form/Element/ExtensibleSet.php | 2 +- library/Director/Web/Form/IplElement/ExtensibleSetElement.php | 4 ++-- library/Director/Web/Table/BasketSnapshotTable.php | 2 +- 27 files changed, 29 insertions(+), 29 deletions(-) diff --git a/application/controllers/SelfServiceController.php b/application/controllers/SelfServiceController.php index 0b3b642f..6479a298 100644 --- a/application/controllers/SelfServiceController.php +++ b/application/controllers/SelfServiceController.php @@ -194,7 +194,7 @@ class SelfServiceController extends ActionController } else { throw new ProgrammingError( 'Expected boolean value, got %s', - var_export($value, 1) + var_export($value, true) ); } } diff --git a/library/Director/Core/RestApiResponse.php b/library/Director/Core/RestApiResponse.php index 523ed35b..43516f7e 100644 --- a/library/Director/Core/RestApiResponse.php +++ b/library/Director/Core/RestApiResponse.php @@ -113,7 +113,7 @@ class RestApiResponse throw new IcingaException('API request failed: ' . $result->status); } } else { - throw new IcingaException('API request failed: ' . var_export($result, 1)); + throw new IcingaException('API request failed: ' . var_export($result, true)); } } diff --git a/library/Director/CustomVariable/CustomVariable.php b/library/Director/CustomVariable/CustomVariable.php index 98eda84d..4b5dd3e4 100644 --- a/library/Director/CustomVariable/CustomVariable.php +++ b/library/Director/CustomVariable/CustomVariable.php @@ -236,7 +236,7 @@ abstract class CustomVariable implements IcingaConfigRenderer // TODO: check for specific class/stdClass/interface? return new CustomVariableDictionary($key, $value); } else { - throw new LogicException(sprintf('WTF (%s): %s', $key, var_export($value, 1))); + throw new LogicException(sprintf('WTF (%s): %s', $key, var_export($value, true))); } } diff --git a/library/Director/CustomVariable/CustomVariableBoolean.php b/library/Director/CustomVariable/CustomVariableBoolean.php index 9953fae7..750f1d66 100644 --- a/library/Director/CustomVariable/CustomVariableBoolean.php +++ b/library/Director/CustomVariable/CustomVariableBoolean.php @@ -31,7 +31,7 @@ class CustomVariableBoolean extends CustomVariable if (! is_bool($value)) { throw new ProgrammingError( 'Expected a boolean, got %s', - var_export($value, 1) + var_export($value, true) ); } diff --git a/library/Director/CustomVariable/CustomVariableNull.php b/library/Director/CustomVariable/CustomVariableNull.php index f87ccfaf..83e07f03 100644 --- a/library/Director/CustomVariable/CustomVariableNull.php +++ b/library/Director/CustomVariable/CustomVariableNull.php @@ -31,7 +31,7 @@ class CustomVariableNull extends CustomVariable if (! is_null($value)) { throw new ProgrammingError( 'Null can only be null, got %s', - var_export($value, 1) + var_export($value, true) ); } diff --git a/library/Director/CustomVariable/CustomVariableNumber.php b/library/Director/CustomVariable/CustomVariableNumber.php index 62838a92..7b0c3e91 100644 --- a/library/Director/CustomVariable/CustomVariableNumber.php +++ b/library/Director/CustomVariable/CustomVariableNumber.php @@ -47,7 +47,7 @@ class CustomVariableNumber extends CustomVariable if (! is_int($value) && ! is_float($value)) { throw new ProgrammingError( 'Expected a number, got %s', - var_export($value, 1) + var_export($value, true) ); } diff --git a/library/Director/Data/Db/DbDataFormatter.php b/library/Director/Data/Db/DbDataFormatter.php index e06af69b..91fc7761 100644 --- a/library/Director/Data/Db/DbDataFormatter.php +++ b/library/Director/Data/Db/DbDataFormatter.php @@ -20,7 +20,7 @@ class DbDataFormatter throw new InvalidArgumentException(sprintf( 'Got invalid boolean: %s', - var_export($value, 1) + var_export($value, true) )); } diff --git a/library/Director/Data/Db/DbObject.php b/library/Director/Data/Db/DbObject.php index e22b8ff0..114b61b9 100644 --- a/library/Director/Data/Db/DbObject.php +++ b/library/Director/Data/Db/DbObject.php @@ -984,7 +984,7 @@ abstract class DbObject $this->table, $this->getLogId(), $e->getMessage(), - var_export($this->getProperties(), 1) // TODO: Remove properties + var_export($this->getProperties(), true) // TODO: Remove properties )); } diff --git a/library/Director/Data/PropertyMangler.php b/library/Director/Data/PropertyMangler.php index a457f1df..40b25704 100644 --- a/library/Director/Data/PropertyMangler.php +++ b/library/Director/Data/PropertyMangler.php @@ -19,7 +19,7 @@ class PropertyMangler throw new InvalidArgumentException(sprintf( 'I can only append to arrays, %s is %s', $key, - var_export($current, 1) + var_export($current, true) )); } @@ -52,7 +52,7 @@ class PropertyMangler throw new InvalidArgumentException(sprintf( 'I can only remove strings or from arrays, %s is %s', $key, - var_export($current, 1) + var_export($current, true) )); } } diff --git a/library/Director/Db/Branch/Branch.php b/library/Director/Db/Branch/Branch.php index 00748ad6..c99b1bdd 100644 --- a/library/Director/Db/Branch/Branch.php +++ b/library/Director/Db/Branch/Branch.php @@ -45,7 +45,7 @@ class Branch $row->uuid = stream_get_contents($row->uuid); } if (strlen($row->uuid) !== 16) { - throw new RuntimeException('Valid UUID expected, got ' . var_export($row->uuid, 1)); + throw new RuntimeException('Valid UUID expected, got ' . var_export($row->uuid, true)); } $self->branchUuid = Uuid::fromBytes(Db\DbUtil::binaryResult($row->uuid)); $self->name = $row->branch_name; diff --git a/library/Director/Db/IcingaObjectFilterHelper.php b/library/Director/Db/IcingaObjectFilterHelper.php index 87f1cc5a..2d9f8f37 100644 --- a/library/Director/Db/IcingaObjectFilterHelper.php +++ b/library/Director/Db/IcingaObjectFilterHelper.php @@ -31,7 +31,7 @@ class IcingaObjectFilterHelper throw new InvalidArgumentException(sprintf( 'Numeric ID or IcingaObject expected, got %s', // TODO: just type/class info? - var_export($id, 1) + var_export($id, true) )); } } diff --git a/library/Director/DirectorObject/Automation/BasketSnapshot.php b/library/Director/DirectorObject/Automation/BasketSnapshot.php index bce55dcb..9638e492 100644 --- a/library/Director/DirectorObject/Automation/BasketSnapshot.php +++ b/library/Director/DirectorObject/Automation/BasketSnapshot.php @@ -410,7 +410,7 @@ class BasketSnapshot extends DbObject try { JsonString::encode($object); } catch (JsonEncodeException $singleError) { - $dump = var_export($object, 1); + $dump = var_export($object, true); if (function_exists('iconv')) { $dump = iconv('UTF-8', 'UTF-8//IGNORE', $dump); } diff --git a/library/Director/IcingaConfig/IcingaConfigHelper.php b/library/Director/IcingaConfig/IcingaConfigHelper.php index 03c017ee..634337f0 100644 --- a/library/Director/IcingaConfig/IcingaConfigHelper.php +++ b/library/Director/IcingaConfig/IcingaConfigHelper.php @@ -177,7 +177,7 @@ class IcingaConfigHelper throw new InvalidArgumentException(sprintf( 'Unexpected type %s', - var_export($value, 1) + var_export($value, true) )); } diff --git a/library/Director/Import/SyncUtils.php b/library/Director/Import/SyncUtils.php index 5528b2de..c106c20b 100644 --- a/library/Director/Import/SyncUtils.php +++ b/library/Director/Import/SyncUtils.php @@ -99,7 +99,7 @@ class SyncUtils throw new InvalidArgumentException(sprintf( 'Data is not nested, cannot access %s: %s', $var, - var_export($row, 1) + var_export($row, true) )); } diff --git a/library/Director/Objects/DirectorDatalistEntry.php b/library/Director/Objects/DirectorDatalistEntry.php index 086686a5..278de97f 100644 --- a/library/Director/Objects/DirectorDatalistEntry.php +++ b/library/Director/Objects/DirectorDatalistEntry.php @@ -51,7 +51,7 @@ class DirectorDatalistEntry extends DbObject } else { throw new RuntimeException( 'Expected array or null for allowed_roles, got %s', - var_export($roles, 1) + var_export($roles, true) ); } } diff --git a/library/Director/Objects/IcingaObjectGroups.php b/library/Director/Objects/IcingaObjectGroups.php index f4288310..8683c778 100644 --- a/library/Director/Objects/IcingaObjectGroups.php +++ b/library/Director/Objects/IcingaObjectGroups.php @@ -228,7 +228,7 @@ class IcingaObjectGroups implements Iterator, Countable, IcingaConfigRenderer } else { throw new RuntimeException( 'Invalid group object: %s', - var_export($group, 1) + var_export($group, true) ); } diff --git a/library/Director/Objects/IcingaObjectMultiRelations.php b/library/Director/Objects/IcingaObjectMultiRelations.php index a1ec9a2c..59315958 100644 --- a/library/Director/Objects/IcingaObjectMultiRelations.php +++ b/library/Director/Objects/IcingaObjectMultiRelations.php @@ -239,7 +239,7 @@ class IcingaObjectMultiRelations implements Iterator, Countable, IcingaConfigRen } else { throw new ProgrammingError( 'Invalid related object: %s', - var_export($relation, 1) + var_export($relation, true) ); } diff --git a/library/Director/Objects/IcingaRelatedObject.php b/library/Director/Objects/IcingaRelatedObject.php index d35bcb0b..ca33688a 100644 --- a/library/Director/Objects/IcingaRelatedObject.php +++ b/library/Director/Objects/IcingaRelatedObject.php @@ -180,7 +180,7 @@ class IcingaRelatedObject } else { throw new ProgrammingError( 'Related object can be name or object, got: %s', - var_export($related, 1) + var_export($related, true) ); } diff --git a/library/Director/Objects/IcingaTemplateChoice.php b/library/Director/Objects/IcingaTemplateChoice.php index 572a9959..a2be07ae 100644 --- a/library/Director/Objects/IcingaTemplateChoice.php +++ b/library/Director/Objects/IcingaTemplateChoice.php @@ -225,7 +225,7 @@ class IcingaTemplateChoice extends IcingaObject implements ExportInterface } else { throw new ProgrammingError( 'Expected array or null for allowed_roles, got %s', - var_export($roles, 1) + var_export($roles, true) ); } } diff --git a/library/Director/PlainObjectRenderer.php b/library/Director/PlainObjectRenderer.php index 4dadf4f4..e613f1f9 100644 --- a/library/Director/PlainObjectRenderer.php +++ b/library/Director/PlainObjectRenderer.php @@ -105,7 +105,7 @@ class PlainObjectRenderer } elseif (is_string($object)) { return self::renderString($object); } else { - return '(UNKNOWN TYPE) ' . var_export($object, 1); + return '(UNKNOWN TYPE) ' . var_export($object, true); } } diff --git a/library/Director/PropertyModifier/PropertyModifierArrayFilter.php b/library/Director/PropertyModifier/PropertyModifierArrayFilter.php index 0b52987e..a8fcbf71 100644 --- a/library/Director/PropertyModifier/PropertyModifierArrayFilter.php +++ b/library/Director/PropertyModifier/PropertyModifierArrayFilter.php @@ -116,7 +116,7 @@ class PropertyModifierArrayFilter extends PropertyModifierHook default: throw new ConfigurationError( '%s is not a valid value for an ArrayFilter filter_method', - var_export($method, 1) + var_export($method, true) ); } diff --git a/library/Director/PropertyModifier/PropertyModifierExtractFromDN.php b/library/Director/PropertyModifier/PropertyModifierExtractFromDN.php index c79c5b2b..6b0651dc 100644 --- a/library/Director/PropertyModifier/PropertyModifierExtractFromDN.php +++ b/library/Director/PropertyModifier/PropertyModifierExtractFromDN.php @@ -74,7 +74,7 @@ class PropertyModifierExtractFromDN extends PropertyModifierHook default: throw new InvalidPropertyException( 'DN part extraction failed for %s', - var_export($value, 1) + var_export($value, true) ); } } diff --git a/library/Director/PropertyModifier/PropertyModifierRejectOrSelect.php b/library/Director/PropertyModifier/PropertyModifierRejectOrSelect.php index 1485d5d4..04c49c57 100644 --- a/library/Director/PropertyModifier/PropertyModifierRejectOrSelect.php +++ b/library/Director/PropertyModifier/PropertyModifierRejectOrSelect.php @@ -128,7 +128,7 @@ class PropertyModifierRejectOrSelect extends PropertyModifierHook default: throw new ConfigurationError( '%s is not a valid value for an ArrayFilter filter_method', - var_export($method, 1) + var_export($method, true) ); } diff --git a/library/Director/RestApi/RestApiClient.php b/library/Director/RestApi/RestApiClient.php index 2ebc4d47..562e393a 100644 --- a/library/Director/RestApi/RestApiClient.php +++ b/library/Director/RestApi/RestApiClient.php @@ -287,7 +287,7 @@ class RestApiClient if ($statusCode >= 400) { throw new RuntimeException( - "Got $statusCode: " . \var_export($res, 1) + "Got $statusCode: " . \var_export($res, true) ); } diff --git a/library/Director/Web/Form/Element/ExtensibleSet.php b/library/Director/Web/Form/Element/ExtensibleSet.php index f3c968fc..e443b06d 100644 --- a/library/Director/Web/Form/Element/ExtensibleSet.php +++ b/library/Director/Web/Form/Element/ExtensibleSet.php @@ -28,7 +28,7 @@ class ExtensibleSet extends FormElement if (! is_array($value)) { throw new InvalidArgumentException(sprintf( 'ExtensibleSet expects to work with Arrays, got %s', - var_export($value, 1) + var_export($value, true) )); } $value = array_filter($value, 'strlen'); diff --git a/library/Director/Web/Form/IplElement/ExtensibleSetElement.php b/library/Director/Web/Form/IplElement/ExtensibleSetElement.php index 5df4983e..b723d47c 100644 --- a/library/Director/Web/Form/IplElement/ExtensibleSetElement.php +++ b/library/Director/Web/Form/IplElement/ExtensibleSetElement.php @@ -111,7 +111,7 @@ class ExtensibleSetElement extends BaseHtmlElement if (null !== $value && ! is_array($value)) { throw new ProgrammingError( 'Got unexpected value, no array: %s', - var_export($value, 1) + var_export($value, true) ); } @@ -325,7 +325,7 @@ class ExtensibleSetElement extends BaseHtmlElement } else { return \sprintf( $this->translate('%s (not an Array!)'), - \var_export($this->inherited, 1) + \var_export($this->inherited, true) ); } } diff --git a/library/Director/Web/Table/BasketSnapshotTable.php b/library/Director/Web/Table/BasketSnapshotTable.php index 08f808ab..72a855ca 100644 --- a/library/Director/Web/Table/BasketSnapshotTable.php +++ b/library/Director/Web/Table/BasketSnapshotTable.php @@ -67,7 +67,7 @@ class BasketSnapshotTable extends ZfQueryBasedTable if (! is_object($summary) && ! is_array($summary)) { throw new RuntimeException(sprintf( 'Got invalid basket summary: %s ', - var_export($summary, 1) + var_export($summary, true) )); } From c9e78ba7d593f6a73ab0f62131b4dd0a0a3a84cb Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 17 Jan 2024 15:05:59 +0100 Subject: [PATCH 04/10] IcingaObjectLegacyAssignments: Fix incorrect if condition --- library/Director/Objects/IcingaObjectLegacyAssignments.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Director/Objects/IcingaObjectLegacyAssignments.php b/library/Director/Objects/IcingaObjectLegacyAssignments.php index 6ab75c87..2db29b49 100644 --- a/library/Director/Objects/IcingaObjectLegacyAssignments.php +++ b/library/Director/Objects/IcingaObjectLegacyAssignments.php @@ -36,7 +36,7 @@ class IcingaObjectLegacyAssignments $assigns = array(); $ignores = array(); foreach ($values as $type => $value) { - if (strpos($value, '|') !== false || strpos($value, '&' !== false)) { + if (strpos($value, '|') !== false || strpos($value, '&') !== false) { $value = '(' . $value . ')'; } From cc3bfd54373d5a90834d76d9368149189c2a646b Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 17 Jan 2024 16:40:19 +0100 Subject: [PATCH 05/10] BranchHelper: Define method return types --- .../Director/Web/Controller/BranchHelper.php | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/library/Director/Web/Controller/BranchHelper.php b/library/Director/Web/Controller/BranchHelper.php index 501f83e7..89aa6c10 100644 --- a/library/Director/Web/Controller/BranchHelper.php +++ b/library/Director/Web/Controller/BranchHelper.php @@ -9,6 +9,7 @@ use Icinga\Module\Director\Db\Branch\BranchSupport; use Icinga\Module\Director\Db\Branch\PreferredBranchSupport; use Icinga\Module\Director\Objects\IcingaObject; use Icinga\Module\Director\Web\Widget\NotInBranchedHint; +use Ramsey\Uuid\UuidInterface; trait BranchHelper { @@ -22,14 +23,17 @@ trait BranchHelper protected $hasPreferredBranch = null; /** - * @return false|\Ramsey\Uuid\UuidInterface + * @return ?UuidInterface */ - protected function getBranchUuid() + protected function getBranchUuid(): ?UuidInterface { return $this->getBranch()->getUuid(); } - protected function getBranch() + /** + * @return Branch + */ + protected function getBranch(): Branch { if ($this->branch === null) { /** @var ActionController $this */ @@ -42,7 +46,7 @@ trait BranchHelper /** * @return BranchStore */ - protected function getBranchStore() + protected function getBranchStore(): BranchStore { if ($this->branchStore === null) { $this->branchStore = new BranchStore($this->db()); @@ -51,12 +55,15 @@ trait BranchHelper return $this->branchStore; } - protected function hasBranch() + /** + * @return bool + */ + protected function hasBranch(): bool { return $this->getBranchUuid() !== null; } - protected function enableStaticObjectLoader($table) + protected function enableStaticObjectLoader($table): void { if (BranchSupport::existsForTableName($table)) { IcingaObject::setDbObjectStore(new DbObjectStore($this->db(), $this->getBranch())); @@ -67,7 +74,7 @@ trait BranchHelper * @param string $subject * @return bool */ - protected function showNotInBranch($subject) + protected function showNotInBranch($subject): bool { if ($this->getBranch()->isBranch()) { $this->content()->add(new NotInBranchedHint($subject, $this->getBranch(), $this->Auth())); @@ -77,7 +84,7 @@ trait BranchHelper return false; } - protected function hasPreferredBranch() + protected function hasPreferredBranch(): bool { if ($this->hasPreferredBranch === null) { $implementation = Branch::optionalHook(); From 2acfdecb8d01d45827e47c29c2bf4fccee33a282 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Thu, 18 Jan 2024 11:44:27 +0100 Subject: [PATCH 06/10] RestApiClient: Remove curl's return type hint and wrong curl_error() param Php >= 8 returns CurlHandle instead of resource, which confuses phpstan. --- library/Director/Core/RestApiClient.php | 14 ++++++-------- library/Director/RestApi/RestApiClient.php | 7 +++---- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/library/Director/Core/RestApiClient.php b/library/Director/Core/RestApiClient.php index b0854ff4..19f6b68b 100644 --- a/library/Director/Core/RestApiClient.php +++ b/library/Director/Core/RestApiClient.php @@ -206,14 +206,14 @@ class RestApiClient } /** - * @return resource + * @throws RuntimeException */ protected function curl() { if ($this->curl === null) { $this->curl = curl_init(sprintf('https://%s:%d', $this->peer, $this->port)); if (! $this->curl) { - throw new RuntimeException('CURL INIT ERROR: ' . curl_error($this->curl)); + throw new RuntimeException('CURL INIT FAILED'); } } @@ -260,13 +260,11 @@ class RestApiClient public function disconnect() { - if ($this->curl !== null) { - if (is_resource($this->curl)) { - @curl_close($this->curl); - } - - $this->curl = null; + if ($this->curl) { + @curl_close($this->curl); } + + $this->curl = null; } public function __destruct() diff --git a/library/Director/RestApi/RestApiClient.php b/library/Director/RestApi/RestApiClient.php index 562e393a..6dcf93c9 100644 --- a/library/Director/RestApi/RestApiClient.php +++ b/library/Director/RestApi/RestApiClient.php @@ -8,7 +8,6 @@ use RuntimeException; class RestApiClient { - /** @var resource */ private $curl; /** @var string HTTP or HTTPS */ @@ -295,14 +294,14 @@ class RestApiClient } /** - * @return resource + * @throws RuntimeException */ protected function curl() { if ($this->curl === null) { - $this->curl = \curl_init(\sprintf('https://%s:%d', $this->host, $this->port)); + $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port)); if (! $this->curl) { - throw new RuntimeException('CURL INIT ERROR: ' . \curl_error($this->curl)); + throw new RuntimeException('CURL INIT FAILED'); } } From 3fc16910f76c3e1adc60cc895a9cfc0df07894b1 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Thu, 18 Jan 2024 12:25:54 +0100 Subject: [PATCH 07/10] `Ini_set()` #param 2 must be string (php < 8.1) --- library/Director/Cli/Command.php | 4 ++-- library/Director/Db/Migrations.php | 2 +- library/Director/IcingaConfig/IcingaConfig.php | 4 ++-- library/Director/Import/Sync.php | 2 +- library/Director/Objects/ImportSource.php | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/library/Director/Cli/Command.php b/library/Director/Cli/Command.php index 69d61b1d..7268913d 100644 --- a/library/Director/Cli/Command.php +++ b/library/Director/Cli/Command.php @@ -82,9 +82,9 @@ class Command extends CliCommand { MemoryLimit::raiseTo('1024M'); - ini_set('max_execution_time', 0); + ini_set('max_execution_time', '0'); if (version_compare(PHP_VERSION, '7.0.0') < 0) { - ini_set('zend.enable_gc', 0); + ini_set('zend.enable_gc', '0'); } return $this; diff --git a/library/Director/Db/Migrations.php b/library/Director/Db/Migrations.php index 2310408c..ad59329b 100644 --- a/library/Director/Db/Migrations.php +++ b/library/Director/Db/Migrations.php @@ -90,7 +90,7 @@ class Migrations public function applyPendingMigrations() { // Ensure we have enough time to migrate - ini_set('max_execution_time', 0); + ini_set('max_execution_time', '0'); foreach ($this->getPendingMigrations() as $migration) { $migration->apply($this->connection); diff --git a/library/Director/IcingaConfig/IcingaConfig.php b/library/Director/IcingaConfig/IcingaConfig.php index a003eafb..a79bf3c7 100644 --- a/library/Director/IcingaConfig/IcingaConfig.php +++ b/library/Director/IcingaConfig/IcingaConfig.php @@ -448,9 +448,9 @@ class IcingaConfig $start = microtime(true); MemoryLimit::raiseTo('1024M'); - ini_set('max_execution_time', 0); + ini_set('max_execution_time', '0'); // Workaround for https://bugs.php.net/bug.php?id=68606 or similar - ini_set('zend.enable_gc', 0); + ini_set('zend.enable_gc', '0'); if (! $this->connection->isPgsql() && $this->db->quote("1\0") !== '\'1\\0\'') { throw new RuntimeException( diff --git a/library/Director/Import/Sync.php b/library/Director/Import/Sync.php index 37a690ef..2957433f 100644 --- a/library/Director/Import/Sync.php +++ b/library/Director/Import/Sync.php @@ -154,7 +154,7 @@ class Sync protected function raiseLimits() { MemoryLimit::raiseTo('1024M'); - ini_set('max_execution_time', 0); + ini_set('max_execution_time', '0'); return $this; } diff --git a/library/Director/Objects/ImportSource.php b/library/Director/Objects/ImportSource.php index 880ae66a..7477472e 100644 --- a/library/Director/Objects/ImportSource.php +++ b/library/Director/Objects/ImportSource.php @@ -479,7 +479,7 @@ class ImportSource extends DbObjectWithSettings implements ExportInterface protected function raiseLimits() { MemoryLimit::raiseTo('1024M'); - ini_set('max_execution_time', 0); + ini_set('max_execution_time', '0'); return $this; } From d879186f0e9ed30c22ccf8176fb30d8b823c63b1 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 17 Jan 2024 16:16:31 +0100 Subject: [PATCH 08/10] Fix wrong method param types and add var type hints --- application/controllers/ConfigController.php | 2 +- .../controllers/SelfServiceController.php | 4 ++-- application/forms/SyncCheckForm.php | 2 +- application/views/helpers/FormDataFilter.php | 16 +++++++++------- library/Director/Cli/ObjectCommand.php | 2 +- library/Director/Core/CoreApi.php | 2 +- library/Director/Core/LegacyDeploymentApi.php | 10 +++++++--- library/Director/Daemon/BackgroundDaemon.php | 2 +- .../DirectorObject/ObjectPurgeHelper.php | 4 ++-- library/Director/Import/ImportSourceRestApi.php | 1 + library/Director/Objects/IcingaCommand.php | 6 ++---- .../PropertyModifierGetHostByName.php | 3 ++- .../Director/ProvidedHook/IcingaDbCubeLinks.php | 13 ++++++++----- library/Director/RestApi/RestApiParams.php | 3 ++- library/Director/StartupLogRenderer.php | 4 +++- .../Web/Controller/ObjectsController.php | 3 ++- library/Director/Web/Form/CsrfToken.php | 2 +- library/Director/Web/Form/DbSelectorForm.php | 2 +- library/Director/Web/Form/DirectorObjectForm.php | 5 ++++- .../Web/Widget/IcingaObjectInspection.php | 2 +- 20 files changed, 52 insertions(+), 36 deletions(-) diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index 8e6febef..8a5e702d 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -370,7 +370,7 @@ class ConfigController extends ActionController $configs = $db->enumDeployedConfigs(); foreach (array($leftSum, $rightSum) as $sum) { - if (! array_key_exists($sum, $configs)) { + if ($sum && ! array_key_exists($sum, $configs)) { $configs[$sum] = substr($sum, 0, 7); } } diff --git a/application/controllers/SelfServiceController.php b/application/controllers/SelfServiceController.php index 6479a298..c3c9bb5a 100644 --- a/application/controllers/SelfServiceController.php +++ b/application/controllers/SelfServiceController.php @@ -275,7 +275,7 @@ class SelfServiceController extends ActionController // PluginsUrl => framework_plugins_url ]; $username = $settings->get('self-service/icinga_service_user'); - if ($username !== null && strlen($username) > 0) { + if ($username) { $params['icinga_service_user'] = $username; } @@ -404,7 +404,7 @@ class SelfServiceController extends ActionController { foreach ($keys as $key) { $value = $settings->get("self-service/$key"); - if (strlen($value)) { + if ($value) { $params[$key] = $value; } } diff --git a/application/forms/SyncCheckForm.php b/application/forms/SyncCheckForm.php index 8fb3bd0c..b180d3d3 100644 --- a/application/forms/SyncCheckForm.php +++ b/application/forms/SyncCheckForm.php @@ -55,7 +55,7 @@ class SyncCheckForm extends DirectorForm } elseif ($sum['modify'] > 1) { } */ - $html = '
' . print_r($sum, 1) . '
'; + $html = '
' . print_r($sum, true) . '
'; $this->addHtml($html); } elseif ($this->rule->get('sync_state') === 'in-sync') { diff --git a/application/views/helpers/FormDataFilter.php b/application/views/helpers/FormDataFilter.php index f4924d06..a62b906d 100644 --- a/application/views/helpers/FormDataFilter.php +++ b/application/views/helpers/FormDataFilter.php @@ -44,14 +44,16 @@ class Zend_View_Helper_FormDataFilter extends Zend_View_Helper_FormElement { $info = $this->_getInfo($name, $value, $attribs); extract($info); // id, name, value, attribs, options, listsep, disable - if (array_key_exists('columns', $attribs)) { - $this->setColumns($attribs['columns']); - unset($attribs['columns']); - } + if ($attribs) { + if (array_key_exists('columns', $attribs)) { + $this->setColumns($attribs['columns']); + unset($attribs['columns']); + } - if (array_key_exists('suggestionContext', $attribs)) { - $this->setSuggestionContext($attribs['suggestionContext']); - unset($attribs['suggestionContext']); + if (array_key_exists('suggestionContext', $attribs)) { + $this->setSuggestionContext($attribs['suggestionContext']); + unset($attribs['suggestionContext']); + } } // TODO: check for columns in attribs, preserve & remove them from the diff --git a/library/Director/Cli/ObjectCommand.php b/library/Director/Cli/ObjectCommand.php index ca68213d..ed99c149 100644 --- a/library/Director/Cli/ObjectCommand.php +++ b/library/Director/Cli/ObjectCommand.php @@ -428,7 +428,7 @@ class ObjectCommand extends Command } $stdin = file_get_contents('php://stdin'); - if (strlen($stdin) === 0) { + if (! $stdin) { return null; } diff --git a/library/Director/Core/CoreApi.php b/library/Director/Core/CoreApi.php index c1229665..73588c20 100644 --- a/library/Director/Core/CoreApi.php +++ b/library/Director/Core/CoreApi.php @@ -569,7 +569,7 @@ constants 'icon_image_alt' => 'icon_image_alt', ]; - if (version_compare($this->getVersion(), '2.8.0', '>=')) { + if (version_compare($this->getVersion() ?? '', '2.8.0', '>=')) { $params['flapping_threshold_high'] = 'flapping_threshold_high'; $params['flapping_threshold_low'] = 'flapping_threshold_low'; } diff --git a/library/Director/Core/LegacyDeploymentApi.php b/library/Director/Core/LegacyDeploymentApi.php index 7287c4a7..0ab77e03 100644 --- a/library/Director/Core/LegacyDeploymentApi.php +++ b/library/Director/Core/LegacyDeploymentApi.php @@ -128,6 +128,10 @@ class LegacyDeploymentApi implements DeploymentApiInterface if (file_exists($path)) { if (is_link($path)) { $linkTarget = readlink($path); + if (! $linkTarget) { + throw new IcingaException('Failed to read symlink'); + } + $linkTargetDir = dirname($linkTarget); $linkTargetName = basename($linkTarget); @@ -165,7 +169,7 @@ class LegacyDeploymentApi implements DeploymentApiInterface $this->assertDeploymentPath(); $dh = @opendir($this->deploymentPath); - if ($dh === null) { + if ($dh === false) { throw new IcingaException('Can not list contents of %s', $this->deploymentPath); } @@ -279,7 +283,7 @@ class LegacyDeploymentApi implements DeploymentApiInterface $this->mkdir(dirname($fullPath), true); $fh = @fopen($fullPath, 'w'); - if ($fh === null) { + if ($fh === false) { throw new IcingaException('Could not open file "%s" for writing.', $fullPath); } chmod($fullPath, $this->file_mode); @@ -334,7 +338,7 @@ class LegacyDeploymentApi implements DeploymentApiInterface protected function listDirectoryContents($path, $depth = 0) { $dh = @opendir($path); - if ($dh === null) { + if ($dh === false) { throw new IcingaException('Can not list contents of %s', $path); } diff --git a/library/Director/Daemon/BackgroundDaemon.php b/library/Director/Daemon/BackgroundDaemon.php index 34cc28b7..2d8a29c5 100644 --- a/library/Director/Daemon/BackgroundDaemon.php +++ b/library/Director/Daemon/BackgroundDaemon.php @@ -104,7 +104,7 @@ class BackgroundDaemon try { $uuid = \bin2hex(Uuid::uuid4()->getBytes()); } catch (Exception $e) { - $uuid = 'deadc0de' . \substr(\md5(\getmypid()), 0, 24); + $uuid = 'deadc0de' . substr(md5((string) getmypid()), 0, 24); } } $processDetails = new DaemonProcessDetails($uuid); diff --git a/library/Director/DirectorObject/ObjectPurgeHelper.php b/library/Director/DirectorObject/ObjectPurgeHelper.php index a043965d..5e507271 100644 --- a/library/Director/DirectorObject/ObjectPurgeHelper.php +++ b/library/Director/DirectorObject/ObjectPurgeHelper.php @@ -44,11 +44,11 @@ class ObjectPurgeHelper // TODO: this is object-specific and to be found in the ::import() function! unset($properties['fields']); $object = $class::fromPlainObject($properties); - } elseif (\get_class($object) !== $class) { + } elseif (get_class($object) !== $class) { throw new InvalidArgumentException( 'Can keep only matching objects, expected "%s", got "%s', $class, - \get_class($keep) + get_class($object) ); } $key = []; diff --git a/library/Director/Import/ImportSourceRestApi.php b/library/Director/Import/ImportSourceRestApi.php index dc772e1e..45f7351a 100644 --- a/library/Director/Import/ImportSourceRestApi.php +++ b/library/Director/Import/ImportSourceRestApi.php @@ -69,6 +69,7 @@ class ImportSourceRestApi extends ImportSourceHook $data = $result; foreach ($parts as $part) { // un-escape any dots + /** @var string $part */ $part = preg_replace('~\\\\.~', '.', $part); if (property_exists($data, $part)) { diff --git a/library/Director/Objects/IcingaCommand.php b/library/Director/Objects/IcingaCommand.php index 81cac9ed..8c5aed0e 100644 --- a/library/Director/Objects/IcingaCommand.php +++ b/library/Director/Objects/IcingaCommand.php @@ -127,10 +127,8 @@ class IcingaCommand extends IcingaObject implements ObjectWithArguments, ExportI // return $value; } - if (self::$pluginDir !== null) { - if (($pos = strpos($value, self::$pluginDir)) === 0) { - $value = substr($value, strlen(self::$pluginDir) + 1); - } + if (isset($value, self::$pluginDir) && strpos($value, self::$pluginDir) === 0) { + $value = substr($value, strlen(self::$pluginDir) + 1); } return $value; diff --git a/library/Director/PropertyModifier/PropertyModifierGetHostByName.php b/library/Director/PropertyModifier/PropertyModifierGetHostByName.php index 36884e85..d7921dea 100644 --- a/library/Director/PropertyModifier/PropertyModifierGetHostByName.php +++ b/library/Director/PropertyModifier/PropertyModifierGetHostByName.php @@ -34,7 +34,8 @@ class PropertyModifierGetHostByName extends PropertyModifierHook } $host = gethostbyname($value); - if (strlen(@inet_pton($host)) !== 4) { + $inAddr = inet_pton($host); + if (! $inAddr || strlen($inAddr) !== 4) { switch ($this->getSetting('on_failure')) { case 'null': return null; diff --git a/library/Director/ProvidedHook/IcingaDbCubeLinks.php b/library/Director/ProvidedHook/IcingaDbCubeLinks.php index 234f61fb..f3fe4029 100644 --- a/library/Director/ProvidedHook/IcingaDbCubeLinks.php +++ b/library/Director/ProvidedHook/IcingaDbCubeLinks.php @@ -7,6 +7,7 @@ use Icinga\Exception\ProgrammingError; use Icinga\Module\Cube\Hook\IcingaDbActionsHook; use Icinga\Module\Cube\IcingaDb\IcingaDbCube; use Icinga\Module\Cube\IcingaDb\IcingaDbHostStatusCube; +use ipl\Stdlib\Filter\Condition; class IcingaDbCubeLinks extends IcingaDbActionsHook { @@ -25,17 +26,19 @@ class IcingaDbCubeLinks extends IcingaDbActionsHook if ($filterChain->count() === 1) { $url = 'director/host/edit?'; - $params = ['name' => $filterChain->getIterator()->current()->getValue()]; + /** @var Condition $rule */ + $rule = $filterChain->getIterator()->current(); + /** @var string $name */ + $name = $rule->getValue(); + $params = ['name' => $name]; $title = t('Modify a host'); - $description = sprintf( - t('This allows you to modify properties for "%s"'), - $filterChain->getIterator()->current()->getValue() - ); + $description = sprintf(t('This allows you to modify properties for "%s"'), $name); } else { $params = null; $urlFilter = Filter::matchAny(); + /** @var Condition $filter */ foreach ($filterChain as $filter) { $urlFilter->addFilter( Filter::matchAny( diff --git a/library/Director/RestApi/RestApiParams.php b/library/Director/RestApi/RestApiParams.php index c237ac51..741eeed1 100644 --- a/library/Director/RestApi/RestApiParams.php +++ b/library/Director/RestApi/RestApiParams.php @@ -19,8 +19,9 @@ class RestApiParams } $exporter->enableHostServices(); } + /** @var ?string $properties */ $properties = $params->shift('properties'); - if ($properties !== null && strlen($properties)) { + if ($properties) { $exporter->filterProperties(preg_split('/\s*,\s*/', $properties, -1, PREG_SPLIT_NO_EMPTY)); } $exporter->resolveObjects($resolved); diff --git a/library/Director/StartupLogRenderer.php b/library/Director/StartupLogRenderer.php index d9b532a7..9d5810fe 100644 --- a/library/Director/StartupLogRenderer.php +++ b/library/Director/StartupLogRenderer.php @@ -33,7 +33,9 @@ class StartupLogRenderer implements ValidHtml // len [stage] + 1 $markReplace = ' ^'; - foreach (preg_split('/\n/', $log) as $line) { + /** @var string[] $logLines */ + $logLines = preg_split('/\n/', $log); + foreach ($logLines as $line) { if (preg_match('/^\[([\d\s\:\+\-]+)\]\s/', $line, $m)) { $time = $m[1]; // TODO: we might use new DateTime($time) and show a special "timeAgo" diff --git a/library/Director/Web/Controller/ObjectsController.php b/library/Director/Web/Controller/ObjectsController.php index c45ef021..c4c96c5b 100644 --- a/library/Director/Web/Controller/ObjectsController.php +++ b/library/Director/Web/Controller/ObjectsController.php @@ -85,8 +85,9 @@ abstract class ObjectsController extends ActionController } elseif ($request->getActionName() === 'applyrules') { $table->filterObjectType('apply'); } + /** @var ?string $search */ $search = $this->params->get('q'); - if ($search !== null && \strlen($search) > 0) { + if ($search) { $table->search($search); } diff --git a/library/Director/Web/Form/CsrfToken.php b/library/Director/Web/Form/CsrfToken.php index 24edf88f..f6c29ec9 100644 --- a/library/Director/Web/Form/CsrfToken.php +++ b/library/Director/Web/Form/CsrfToken.php @@ -17,7 +17,7 @@ class CsrfToken return false; } - list($seed, $token) = explode('|', $elementValue); + list($seed, $token) = explode('|', $token); if (!is_numeric($seed)) { return false; diff --git a/library/Director/Web/Form/DbSelectorForm.php b/library/Director/Web/Form/DbSelectorForm.php index 52fe5ea3..8b4f4323 100644 --- a/library/Director/Web/Form/DbSelectorForm.php +++ b/library/Director/Web/Form/DbSelectorForm.php @@ -69,7 +69,7 @@ class DbSelectorForm extends Form $params = []; } - if (array_key_exists($name, $params)) { + if (is_array($params) && array_key_exists($name, $params)) { return $params[$name]; } diff --git a/library/Director/Web/Form/DirectorObjectForm.php b/library/Director/Web/Form/DirectorObjectForm.php index 85562468..abbd4f09 100644 --- a/library/Director/Web/Form/DirectorObjectForm.php +++ b/library/Director/Web/Form/DirectorObjectForm.php @@ -791,7 +791,9 @@ abstract class DirectorObjectForm extends DirectorForm return; } - $post = $values = $this->getRequest()->getPost(); + /** @var array $post */ + $post = $this->getRequest()->getPost(); + $values = $post; foreach ($post as $key => $value) { if (preg_match('/^(.+?)_(\d+)__(MOVE_DOWN|MOVE_UP|REMOVE)$/', $key, $m)) { @@ -1519,6 +1521,7 @@ abstract class DirectorObjectForm extends DirectorForm return []; } + /** @var int|string $id */ $id = $object->get('id'); if (array_key_exists($id, $tpl)) { diff --git a/library/Director/Web/Widget/IcingaObjectInspection.php b/library/Director/Web/Widget/IcingaObjectInspection.php index 61f35671..d9cf69dd 100644 --- a/library/Director/Web/Widget/IcingaObjectInspection.php +++ b/library/Director/Web/Widget/IcingaObjectInspection.php @@ -205,7 +205,7 @@ class IcingaObjectInspection extends BaseHtmlElement $this->add(Html::tag('p')->add(Html::sprintf( 'The configuration for this object has been rendered by Icinga' . ' Director %s to %s', - DateFormatter::timeAgo(strtotime($deployment->start_time, false)), + DateFormatter::timeAgo(strtotime($deployment->start_time)), $this->linkToSourceLocation($deployment, $source) ))); } From bcdb8911f979ba04a59a3b543855276846df1630 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Fri, 19 Jan 2024 14:27:26 +0100 Subject: [PATCH 09/10] Update phpstan-baseline --- phpstan-baseline.neon | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 424432bf..259e9406 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -505,11 +505,6 @@ parameters: count: 1 path: library/Director/PropertyModifier/PropertyModifierRejectOrSelect.php - - - message: "#^Call to an undefined method ipl\\\\Stdlib\\\\Filter\\\\Rule\\:\\:getValue\\(\\)\\.$#" - count: 3 - path: library/Director/ProvidedHook/IcingaDbCubeLinks.php - - message: "#^Access to an undefined property Zend_Controller_Action_HelperBroker\\:\\:\\$viewRenderer\\.$#" count: 1 @@ -590,11 +585,6 @@ parameters: count: 1 path: library/Director/Web/Controller/TemplateController.php - - - message: "#^Undefined variable\\: \\$elementValue$#" - count: 1 - path: library/Director/Web/Form/CsrfToken.php - - message: "#^Call to an undefined method Icinga\\\\Module\\\\Director\\\\Data\\\\Db\\\\DbObject\\:\\:getShortTableName\\(\\)\\.$#" count: 1 From 9cccd9067e09bab6f8f5a4d93512686ca8b0f846 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Mon, 22 Jan 2024 09:54:32 +0100 Subject: [PATCH 10/10] phpstan: Scan all available modules --- phpstan.neon | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index b61aa70a..c02492f8 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -22,9 +22,7 @@ parameters: scanDirectories: - /icingaweb2 - /usr/share/icinga-php - - /usr/share/icingaweb2-modules/incubator - - /usr/share/icingaweb2-modules/cube - - /usr/share/icingaweb2-modules/icingadb + - /usr/share/icingaweb2-modules excludePaths: - library/Director/CoreBeta