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 ( b1a01a...cadd6b )
by Talv
10:35
created

Notification   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A via() 0 4 1
A setEvent() 0 6 1
A getEvent() 0 4 1
A toMail() 0 10 1
A toSlack() 0 14 1
A toMsTeams() 0 19 1
A throttleDecayMinutes() 0 4 1
A throttleKeyId() 0 9 2
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
    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
        return config('throttled-failed-jobs.channels');
21
    }
22
23
    public function setEvent(JobFailed $event): self
24
    {
25
        $this->event = $event;
26
27
        return $this;
28
    }
29
30
    public function getEvent(): JobFailed
31
    {
32
        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
    ```php
67
        %s
68
    ```
69
        ',
70
            $this->event->exception->getMessage(),
71
            $this->event->job->resolveName(),
72
            $this->event->job->getRawBody(),
73
            $this->event->exception->getTraceAsString()
74
        );
75
76
        return MsTeamsMessage::create()
77
            ->title('A job failed at '.config('app.url'))
78
            ->content($content);
79
    }
80
81
    public function throttleDecayMinutes(): int
82
    {
83
        return config('throttled-failed-jobs.throttle_decay');
84
    }
85
86
    public function throttleKeyId()
87
    {
88
        if ($this->getEvent()->exception instanceof \Exception) {
89
            return Str::kebab($this->getEvent()->exception->getMessage());
90
        }
91
92
        // fall back throttle key, use the notification name...
93
        return static::class;
94
    }
95
}
96