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.

Notification::via()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace TalvBansal\ThrottledFailedJobMonitor;
4
5
use Illuminate\Notifications\Messages\MailMessage;
6
use Illuminate\Notifications\Messages\SlackAttachment;
7
use Illuminate\Notifications\Messages\SlackMessage;
8
use Illuminate\Notifications\Notification as IlluminateNotification;
9
use Illuminate\Queue\Events\JobFailed;
10
use Illuminate\Support\Str;
11
use NotificationChannels\MsTeams\MsTeamsMessage;
12
13
class Notification extends IlluminateNotification implements ThrottledNotification
14
{
15
    /** @var \Illuminate\Queue\Events\JobFailed */
16
    protected $event;
17
18 5
    public function via($notifiable): array
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...
19
    {
20 5
        return config('throttled-failed-jobs.channels');
21
    }
22
23 5
    public function setEvent(JobFailed $event): self
24
    {
25 5
        $this->event = $event;
26
27 5
        return $this;
28
    }
29
30 5
    public function getEvent(): JobFailed
31
    {
32 5
        return $this->event;
33
    }
34
35
    public function toMail($notifiable): MailMessage
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...
36
    {
37
        return (new MailMessage)
38
            ->error()
39
            ->subject('A job failed at '.config('app.url'))
40
            ->line("Exception message: {$this->event->exception->getMessage()}")
41
            ->line("Job class: {$this->event->job->resolveName()}")
42
            ->line("Job body: {$this->event->job->getRawBody()}")
43
            ->line("Exception: {$this->event->exception->getTraceAsString()}");
44
    }
45
46
    public function toSlack(): SlackMessage
47
    {
48
        return (new SlackMessage)
49
            ->error()
50
            ->content('A job failed at '.config('app.url'))
51
            ->attachment(function (SlackAttachment $attachment) {
52
                $attachment->fields([
53
                    'Exception message' => $this->event->exception->getMessage(),
54
                    'Job class' => $this->event->job->resolveName(),
55
                    'Job body' => $this->event->job->getRawBody(),
56
                    'Exception' => $this->event->exception->getTraceAsString(),
57
                ]);
58
            });
59
    }
60
61
    public function toMsTeams(): MsTeamsMessage
62
    {
63
        $content = sprintf('## Job class : %s
64
> Exception message: %s
65
Job body: %s
66
        ',
67
            $this->event->exception->getMessage(),
68
            $this->event->job->resolveName(),
69
            $this->event->job->getRawBody()
70
        );
71
72
        return MsTeamsMessage::create()
73
            ->type('error')
74
            ->title('A job failed at '.config('app.url'))
75
            ->content($content)
76
            ->code($this->event->exception->getTraceAsString());
77
    }
78
79 5
    public function throttleDecayMinutes(): int
80
    {
81 5
        return config('throttled-failed-jobs.throttle_decay');
82
    }
83
84 5
    public function throttleKeyId()
85
    {
86 5
        if ($this->getEvent()->exception instanceof \Exception) {
87 5
            return Str::kebab($this->getEvent()->exception->getMessage());
88
        }
89
90
        // fall back throttle key, use the notification name...
91
        return static::class;
92
    }
93
}
94