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 ( cd2e1a...631600 )
by TJ
01:38
created

UptimeCheckRecovered::isStillRelevant()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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)
0 ignored issues
show
Unused Code introduced by
The parameter $notifiable is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter $notifiable is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
Bug introduced by
It seems like \Carbon\Carbon::now() targeting Carbon\Traits\Creator::now() can also be of type object<Carbon\Traits\Creator>; however, Illuminate\Notifications...Attachment::timestamp() does only seem to accept object<DateTimeInterface...t<DateInterval>|integer, maybe add an additional type check?

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.

Loading history...
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