These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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\SlackMessage; |
||
8 | use Spatie\UptimeMonitor\Models\Enums\UptimeStatus; |
||
9 | use Illuminate\Notifications\Messages\SlackAttachment; |
||
10 | use Spatie\UptimeMonitor\Notifications\BaseNotification; |
||
11 | use Spatie\UptimeMonitor\Events\UptimeCheckRecovered as MonitorRecoveredEvent; |
||
12 | |||
13 | class UptimeCheckRecovered extends BaseNotification |
||
14 | { |
||
15 | /** @var \Spatie\UptimeMonitor\Events\UptimeCheckRecovered */ |
||
16 | public $event; |
||
17 | |||
18 | /** |
||
19 | * Get the mail representation of the notification. |
||
20 | * |
||
21 | * @param mixed $notifiable |
||
22 | * @return \Illuminate\Notifications\Messages\MailMessage |
||
23 | */ |
||
24 | View Code Duplication | public function toMail($notifiable) |
|
25 | { |
||
26 | $mailMessage = (new MailMessage) |
||
27 | ->success() |
||
28 | ->subject($this->getMessageText()) |
||
29 | ->line($this->getMessageText()) |
||
30 | ->line($this->getLocationDescription()); |
||
31 | |||
32 | foreach ($this->getMonitorProperties() as $name => $value) { |
||
33 | $mailMessage->line($name.': '.$value); |
||
34 | } |
||
35 | |||
36 | return $mailMessage; |
||
37 | } |
||
38 | |||
39 | View Code Duplication | public function toSlack($notifiable) |
|
40 | { |
||
41 | return (new SlackMessage) |
||
42 | ->success() |
||
43 | ->attachment(function (SlackAttachment $attachment) { |
||
44 | $attachment |
||
45 | ->title($this->getMessageText()) |
||
46 | ->fallback($this->getMessageText()) |
||
47 | ->footer($this->getLocationDescription()) |
||
48 | ->timestamp(Carbon::now()); |
||
0 ignored issues
–
show
|
|||
49 | }); |
||
50 | } |
||
51 | |||
52 | public function getMonitorProperties($extraProperties = []): array |
||
53 | { |
||
54 | $extraProperties = [ |
||
55 | "Downtime: {$this->event->downtimePeriod->duration()}" => $this->event->downtimePeriod->toText(), |
||
56 | ]; |
||
57 | |||
58 | return parent::getMonitorProperties($extraProperties); |
||
59 | } |
||
60 | |||
61 | public function isStillRelevant(): bool |
||
62 | { |
||
63 | return $this->getMonitor()->uptime_status == UptimeStatus::UP; |
||
64 | } |
||
65 | |||
66 | public function setEvent(MonitorRecoveredEvent $event) |
||
67 | { |
||
68 | $this->event = $event; |
||
69 | |||
70 | return $this; |
||
71 | } |
||
72 | |||
73 | public function getMessageText(): string |
||
74 | { |
||
75 | return "{$this->getMonitor()->url} has recovered after {$this->event->downtimePeriod->duration()}"; |
||
76 | } |
||
77 | } |
||
78 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.