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

CertificateCheckFailed   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 22.41 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 6
dl 13
loc 58
rs 10
c 0
b 0
f 0

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 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\CertificateCheckFailed as InValidCertificateFoundEvent;
10
use Spatie\UptimeMonitor\Notifications\BaseNotification;
11
12
class CertificateCheckFailed extends BaseNotification
13
{
14
    public InValidCertificateFoundEvent $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...
15
16
    /**
17
     * Get the mail representation of the notification.
18
     *
19
     * @param  mixed $notifiable
20
     * @return \Illuminate\Notifications\Messages\MailMessage
21
     */
22
    public function toMail($notifiable)
23
    {
24
        $mailMessage = (new MailMessage)
25
            ->error()
26
            ->subject($this->getMessageText())
27
            ->line($this->getMessageText());
28
29
        foreach ($this->getMonitorProperties() as $name => $value) {
30
            $mailMessage->line($name.': '.$value);
31
        }
32
33
        return $mailMessage;
34
    }
35
36
    public function toSlack($notifiable)
37
    {
38
        return (new SlackMessage)
39
            ->error()
40
            ->attachment(function (SlackAttachment $attachment) {
41
                $attachment
42
                    ->title($this->getMessageText())
43
                    ->content($this->getMonitor()->certificate_check_failure_reason)
44
                    ->fallback($this->getMessageText())
45
                    ->footer($this->getMonitor()->certificate_issuer)
46
                    ->timestamp(Carbon::now());
47
            });
48
    }
49
50
    public function getMonitorProperties($properties = []): array
51
    {
52
        $extraProperties = ['Failure reason' => $this->event->monitor->certificate_check_failure_reason];
53
54
        return parent::getMonitorProperties($extraProperties);
55
    }
56
57
    public function setEvent(InValidCertificateFoundEvent $event): self
58
    {
59
        $this->event = $event;
60
61
        return $this;
62
    }
63
64
    public function getMessageText(): string
65
    {
66
        return "SSL Certificate for {$this->getMonitor()->url} is invalid";
67
    }
68
}
69