From 7d901a44a4218d0d6a6bdcf39afd8d054f2a3d89 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Tue, 23 Jan 2024 09:26:41 +0100 Subject: [PATCH] Fix phpstan's method call on null error --- library/Icingadb/Widget/Detail/DowntimeCard.php | 2 +- library/Icingadb/Widget/Detail/EventDetail.php | 6 +++--- library/Icingadb/Widget/ItemList/BaseDowntimeListItem.php | 6 +++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/library/Icingadb/Widget/Detail/DowntimeCard.php b/library/Icingadb/Widget/Detail/DowntimeCard.php index 81f59dab7..8184479af 100644 --- a/library/Icingadb/Widget/Detail/DowntimeCard.php +++ b/library/Icingadb/Widget/Detail/DowntimeCard.php @@ -35,7 +35,7 @@ public function __construct(Downtime $downtime) $this->start = $this->downtime->scheduled_start_time->getTimestamp(); $this->end = $this->downtime->scheduled_end_time->getTimestamp(); - if ($this->downtime->end_time > $this->downtime->scheduled_end_time) { + if ($this->downtime->end_time && $this->downtime->end_time > $this->downtime->scheduled_end_time) { $this->duration = $this->downtime->end_time->getTimestamp() - $this->start; } else { $this->duration = $this->end - $this->start; diff --git a/library/Icingadb/Widget/Detail/EventDetail.php b/library/Icingadb/Widget/Detail/EventDetail.php index 181c9aead..0b3c09a78 100644 --- a/library/Icingadb/Widget/Detail/EventDetail.php +++ b/library/Icingadb/Widget/Detail/EventDetail.php @@ -366,7 +366,7 @@ protected function assembleDowntimeEvent(DowntimeHistory $downtime) } $cancelInfo = []; - if ($downtime->has_been_cancelled) { + if ($downtime->has_been_cancelled && $downtime->cancel_time) { $cancelInfo = [ new HtmlElement('h2', null, Text::create(t('This downtime has been cancelled'))), new HorizontalKeyValue( @@ -430,7 +430,7 @@ protected function assembleCommentEvent(CommentHistory $comment) } $removedInfo = []; - if ($comment->has_been_removed) { + if ($comment->has_been_removed && $comment->remove_time) { $removedInfo[] = new HtmlElement('h2', null, Text::create(t('This comment has been removed'))); if ($comment->removed_by) { $removedInfo[] = new HorizontalKeyValue( @@ -487,7 +487,7 @@ protected function assembleFlappingEvent(FlappingHistory $flapping) $flapping->percent_state_change_start, $flapping->flapping_threshold_high )); - } else { + } elseif ($flapping->end_time !== null) { $eventInfo[] = new HorizontalKeyValue( t('Ended on'), DateFormatter::formatDateTime($flapping->end_time->getTimestamp()) diff --git a/library/Icingadb/Widget/ItemList/BaseDowntimeListItem.php b/library/Icingadb/Widget/ItemList/BaseDowntimeListItem.php index 7ebc1f6dc..dedaa7215 100644 --- a/library/Icingadb/Widget/ItemList/BaseDowntimeListItem.php +++ b/library/Icingadb/Widget/ItemList/BaseDowntimeListItem.php @@ -56,7 +56,11 @@ abstract class BaseDowntimeListItem extends BaseListItem protected function init(): void { - if ($this->item->is_flexible && $this->item->is_in_effect) { + if ( + isset($this->item->start_time, $this->item->end_time) + && $this->item->is_flexible + && $this->item->is_in_effect + ) { $this->startTime = $this->item->start_time->getTimestamp(); $this->endTime = $this->item->end_time->getTimestamp(); } else {