Skip to content

Commit

Permalink
Fix phpstan's method call on null error
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 authored and nilmerg committed Mar 13, 2024
1 parent 89c0bb0 commit 7d901a4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion library/Icingadb/Widget/Detail/DowntimeCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions library/Icingadb/Widget/Detail/EventDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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())
Expand Down
6 changes: 5 additions & 1 deletion library/Icingadb/Widget/ItemList/BaseDowntimeListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7d901a4

Please sign in to comment.