GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 7f1d39...078202 )
by Freek
03:49 queued 02:41
created

UptimeCheckFailed::toSlack()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Spatie\UptimeMonitor\Notifications\Notifications;
4
5
use Carbon\Carbon;
6
use Illuminate\Notifications\Messages\MailMessage;
7
use Illuminate\Notifications\Messages\SlackAttachment;
8
use Illuminate\Notifications\Messages\SlackMessage;
9
use Spatie\UptimeMonitor\Events\UptimeCheckFailed as MonitorFailedEvent;
10
use Spatie\UptimeMonitor\Models\Enums\UptimeStatus;
11
use Spatie\UptimeMonitor\Notifications\BaseNotification;
12
13
class UptimeCheckFailed extends BaseNotification
14
{
15
    public MonitorFailedEvent $event;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
16
17
    /**
18
     * Get the mail representation of the notification.
19
     *
20
     * @param mixed $notifiable
21
     * @return \Illuminate\Notifications\Messages\MailMessage
22
     */
23
    public function toMail($notifiable)
24
    {
25
        $mailMessage = (new MailMessage)
26
            ->error()
27
            ->subject($this->getMessageText())
28
            ->line($this->getMessageText())
29
            ->line($this->getLocationDescription());
30
31
        foreach ($this->getMonitorProperties() as $name => $value) {
32
            $mailMessage->line($name.': '.$value);
33
        }
34
35
        return $mailMessage;
36
    }
37
38
    public function toSlack($notifiable)
39
    {
40
        return (new SlackMessage)
41
            ->error()
42
            ->attachment(function (SlackAttachment $attachment) {
43
                $attachment
44
                    ->title($this->getMessageText())
45
                    ->content($this->getMonitor()->uptime_check_failure_reason)
46
                    ->fallback($this->getMessageText())
47
                    ->footer($this->getLocationDescription())
48
                    ->timestamp(Carbon::now());
49
            });
50
    }
51
52
    public function getMonitorProperties($extraProperties = []): array
53
    {
54
        $since = "Since {$this->event->downtimePeriod->startDateTime->format('H:i')}";
55
        $date = $this->event->monitor->formattedLastUpdatedStatusChangeDate();
56
57
        $extraProperties = [
58
            $since => $date,
59
            'Failure reason' => $this->getMonitor()->uptime_check_failure_reason,
60
        ];
61
62
        return parent::getMonitorProperties($extraProperties);
63
    }
64
65
    public function isStillRelevant(): bool
66
    {
67
        return $this->getMonitor()->uptime_status == UptimeStatus::DOWN;
68
    }
69
70
    public function setEvent(MonitorFailedEvent $event): self
71
    {
72
        $this->event = $event;
73
74
        return $this;
75
    }
76
77
    protected function getMessageText(): string
78
    {
79
        return "{$this->getMonitor()->url} seems down";
80
    }
81
}
82