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
Pull Request — master (#28)
by Freek
02:04
created

MonitorFailed   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 17.31 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 9
loc 52
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A toMail() 0 9 1
A toSlack() 9 9 1
A getMonitorProperties() 0 8 1
A isStillRelevant() 0 4 1
A setEvent() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Spatie\UptimeMonitor\Notifications\Notifications;
4
5
use Illuminate\Notifications\Messages\MailMessage;
6
use Illuminate\Notifications\Messages\SlackAttachment;
7
use Illuminate\Notifications\Messages\SlackMessage;
8
use Spatie\UptimeMonitor\Events\MonitorFailed as MonitorFailedEvent;
9
use Spatie\UptimeMonitor\Models\Enums\UptimeStatus;
10
use Spatie\UptimeMonitor\Notifications\BaseNotification;
11
12
class MonitorFailed extends BaseNotification
13
{
14
    /** @var \Spatie\UptimeMonitor\Events\MonitorFailed */
15
    public $event;
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)
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...
24
    {
25
        $mailMessage = (new MailMessage)
26
            ->error()
27
            ->subject("The uptime check for monitor {$this->event->monitor->url} failed.")
28
            ->line("The uptime check for monitor {$this->event->monitor->url} failed.");
29
30
        return $mailMessage;
31
    }
32
33 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...
34
    {
35
        return (new SlackMessage)
36
            ->error()
37
            ->content("The uptime check for monitor {$this->event->monitor->url} failed.")
38
            ->attachment(function (SlackAttachment $attachment) {
39
                $attachment->fields($this->getMonitorProperties());
40
            });
41
    }
42
43
    public function getMonitorProperties($extraProperties = []): array
44
    {
45
        $extraProperties = [
46
            'failing since' => $this->event->monitor->formattedLastUpdatedStatusChangeDate,
47
        ];
48
49
        return parent::getMonitorProperties($extraProperties);
50
    }
51
52
    public function isStillRelevant(): bool
53
    {
54
        return $this->event->monitor->uptime_status == UptimeStatus::DOWN;
55
    }
56
57
    public function setEvent(MonitorFailedEvent $event)
58
    {
59
        $this->event = $event;
60
61
        return $this;
62
    }
63
}
64