From 82656de2c2a964dafa4bee77c8f47e4e7c5bdb4c Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sun, 28 Nov 2021 11:13:08 +0100 Subject: [PATCH] Director: some PHP 8.1-related changes --- application/forms/SyncPropertyForm.php | 3 ++- library/Director/IcingaConfig/IcingaConfigHelper.php | 2 +- library/Director/Import/Sync.php | 2 +- library/Director/Objects/IcingaArguments.php | 6 ++++++ library/Director/Objects/IcingaObjectMultiRelations.php | 6 ++++++ library/Director/Objects/IcingaTimePeriodRanges.php | 6 ++++++ library/Director/Web/Table/DatafieldCategoryTable.php | 2 +- library/Director/Web/Widget/ImportSourceDetails.php | 2 +- 8 files changed, 24 insertions(+), 5 deletions(-) diff --git a/application/forms/SyncPropertyForm.php b/application/forms/SyncPropertyForm.php index ba2404a4..720237e9 100644 --- a/application/forms/SyncPropertyForm.php +++ b/application/forms/SyncPropertyForm.php @@ -93,7 +93,8 @@ class SyncPropertyForm extends DirectorObjectForm $this->setElementValue('use_filter', $useFilter = 'n'); } } else { - $useFilter = strlen($this->getObject()->filter_expression) ? 'y' : 'n'; + $expression = $this->getObject()->filter_expression; + $useFilter = ($expression === null || strlen($expression) === 0) ? 'n' : 'y'; $this->setElementValue('use_filter', $useFilter); } diff --git a/library/Director/IcingaConfig/IcingaConfigHelper.php b/library/Director/IcingaConfig/IcingaConfigHelper.php index 79a07bbf..03c017ee 100644 --- a/library/Director/IcingaConfig/IcingaConfigHelper.php +++ b/library/Director/IcingaConfig/IcingaConfigHelper.php @@ -284,7 +284,7 @@ class IcingaConfigHelper return null; } - if (ctype_digit($interval)) { + if (is_int($interval) || ctype_digit($interval)) { return (int) $interval; } diff --git a/library/Director/Import/Sync.php b/library/Director/Import/Sync.php index d3906bc8..23d267d8 100644 --- a/library/Director/Import/Sync.php +++ b/library/Director/Import/Sync.php @@ -184,7 +184,7 @@ class Sync $this->hasPropertyDisabled = true; } - if (! strlen($prop->get('filter_expression'))) { + if ($prop->get('filter_expression') === null || strlen($prop->get('filter_expression')) === 0) { continue; } diff --git a/library/Director/Objects/IcingaArguments.php b/library/Director/Objects/IcingaArguments.php index e87cc18c..d9f9983f 100644 --- a/library/Director/Objects/IcingaArguments.php +++ b/library/Director/Objects/IcingaArguments.php @@ -30,11 +30,13 @@ class IcingaArguments implements Iterator, Countable, IcingaConfigRenderer $this->object = $object; } + #[\ReturnTypeWillChange] public function count() { return count($this->arguments); } + #[\ReturnTypeWillChange] public function rewind() { $this->position = 0; @@ -45,6 +47,7 @@ class IcingaArguments implements Iterator, Countable, IcingaConfigRenderer return $this->modified; } + #[\ReturnTypeWillChange] public function current() { if (! $this->valid()) { @@ -54,16 +57,19 @@ class IcingaArguments implements Iterator, Countable, IcingaConfigRenderer return $this->arguments[$this->idx[$this->position]]; } + #[\ReturnTypeWillChange] public function key() { return $this->idx[$this->position]; } + #[\ReturnTypeWillChange] public function next() { ++$this->position; } + #[\ReturnTypeWillChange] public function valid() { return array_key_exists($this->position, $this->idx); diff --git a/library/Director/Objects/IcingaObjectMultiRelations.php b/library/Director/Objects/IcingaObjectMultiRelations.php index a3d1d519..a1ec9a2c 100644 --- a/library/Director/Objects/IcingaObjectMultiRelations.php +++ b/library/Director/Objects/IcingaObjectMultiRelations.php @@ -57,11 +57,13 @@ class IcingaObjectMultiRelations implements Iterator, Countable, IcingaConfigRen return $this->relations; } + #[\ReturnTypeWillChange] public function count() { return count($this->relations); } + #[\ReturnTypeWillChange] public function rewind() { $this->position = 0; @@ -72,6 +74,7 @@ class IcingaObjectMultiRelations implements Iterator, Countable, IcingaConfigRen return $this->modified; } + #[\ReturnTypeWillChange] public function current() { if (! $this->valid()) { @@ -81,16 +84,19 @@ class IcingaObjectMultiRelations implements Iterator, Countable, IcingaConfigRen return $this->relations[$this->idx[$this->position]]; } + #[\ReturnTypeWillChange] public function key() { return $this->idx[$this->position]; } + #[\ReturnTypeWillChange] public function next() { ++$this->position; } + #[\ReturnTypeWillChange] public function valid() { return array_key_exists($this->position, $this->idx); diff --git a/library/Director/Objects/IcingaTimePeriodRanges.php b/library/Director/Objects/IcingaTimePeriodRanges.php index 7f017bf1..9a9566fe 100644 --- a/library/Director/Objects/IcingaTimePeriodRanges.php +++ b/library/Director/Objects/IcingaTimePeriodRanges.php @@ -30,11 +30,13 @@ class IcingaTimePeriodRanges implements Iterator, Countable, IcingaConfigRendere $this->object = $object; } + #[\ReturnTypeWillChange] public function count() { return count($this->ranges); } + #[\ReturnTypeWillChange] public function rewind() { $this->position = 0; @@ -45,6 +47,7 @@ class IcingaTimePeriodRanges implements Iterator, Countable, IcingaConfigRendere return $this->modified; } + #[\ReturnTypeWillChange] public function current() { if (! $this->valid()) { @@ -54,16 +57,19 @@ class IcingaTimePeriodRanges implements Iterator, Countable, IcingaConfigRendere return $this->ranges[$this->idx[$this->position]]; } + #[\ReturnTypeWillChange] public function key() { return $this->idx[$this->position]; } + #[\ReturnTypeWillChange] public function next() { ++$this->position; } + #[\ReturnTypeWillChange] public function valid() { return array_key_exists($this->position, $this->idx); diff --git a/library/Director/Web/Table/DatafieldCategoryTable.php b/library/Director/Web/Table/DatafieldCategoryTable.php index 3af4fa10..6f07939b 100644 --- a/library/Director/Web/Table/DatafieldCategoryTable.php +++ b/library/Director/Web/Table/DatafieldCategoryTable.php @@ -31,7 +31,7 @@ class DatafieldCategoryTable extends ZfQueryBasedTable ['name' => $row->category_name] )]; - if (strlen($row->description)) { + if ($row->description !== null && strlen($row->description)) { $main[] = Html::tag('br'); $main[] = Html::tag('small', $row->description); } diff --git a/library/Director/Web/Widget/ImportSourceDetails.php b/library/Director/Web/Widget/ImportSourceDetails.php index 829c6a6c..32eef7f0 100644 --- a/library/Director/Web/Widget/ImportSourceDetails.php +++ b/library/Director/Web/Widget/ImportSourceDetails.php @@ -25,7 +25,7 @@ class ImportSourceDetails extends HtmlDocument { $source = $this->source; $description = $source->get('description'); - if (strlen($description)) { + if ($description !== null && strlen($description)) { $this->add(Html::tag('p', null, $description)); }