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 (#12)
by
unknown
01:45
created

Notification::via()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Spatie\FailedJobMonitor;
4
5
use Carbon\Carbon;
6
use Illuminate\Queue\Events\JobFailed;
7
use Illuminate\Notifications\Messages\MailMessage;
8
use Illuminate\Notifications\Messages\SlackMessage;
9
use Illuminate\Notifications\Messages\SlackAttachment;
10
use Illuminate\Notifications\Notification as NotificationBase;
11
12
class Notification extends NotificationBase
13
{
14
    protected $event;
15
16
    public function via($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...
17
    {
18
        return config('laravel-failed-job-monitor.channels');
19
    }
20
21
    public function setEvent(JobFailed $event)
22
    {
23
        $this->event = $event;
24
25
        return $this;
26
    }
27
28
    /**
29
     * Get the mail representation of the notification.
30
     *
31
     * @param  mixed $notifiable
32
     * @return \Illuminate\Notifications\Messages\MailMessage
33
     */
34
    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...
35
    {
36
        return (new MailMessage)
37
            ->subject(trans('laravel-failed-job-monitor::mail.subject'))
0 ignored issues
show
Bug introduced by
It seems like trans('laravel-failed-job-monitor::mail.subject') targeting trans() can also be of type object<Symfony\Component...on\TranslatorInterface>; however, Illuminate\Notifications...impleMessage::subject() does only seem to accept string, 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...
38
            ->greeting(trans('laravel-failed-job-monitor::mail.greeting'))
0 ignored issues
show
Bug introduced by
It seems like trans('laravel-failed-jo...onitor::mail.greeting') targeting trans() can also be of type object<Symfony\Component...on\TranslatorInterface>; however, Illuminate\Notifications...mpleMessage::greeting() does only seem to accept string, 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...
39
            ->line(trans('laravel-failed-job-monitor::mail.intro'))
0 ignored issues
show
Bug introduced by
It seems like trans('laravel-failed-job-monitor::mail.intro') targeting trans() can also be of type object<Symfony\Component...on\TranslatorInterface>; however, Illuminate\Notifications...s\SimpleMessage::line() does only seem to accept object<Illuminate\Notifications\Action>|string, 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...
40
            ->line(trans('laravel-failed-job-monitor::mail.job_info', ['job' => $this->event->job->resolveName()]))
0 ignored issues
show
Bug introduced by
It seems like trans('laravel-failed-jo...t->job->resolveName())) targeting trans() can also be of type object<Symfony\Component...on\TranslatorInterface>; however, Illuminate\Notifications...s\SimpleMessage::line() does only seem to accept object<Illuminate\Notifications\Action>|string, 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...
41
            ->line(trans('laravel-failed-job-monitor::mail.attachment'))
0 ignored issues
show
Bug introduced by
It seems like trans('laravel-failed-jo...itor::mail.attachment') targeting trans() can also be of type object<Symfony\Component...on\TranslatorInterface>; however, Illuminate\Notifications...s\SimpleMessage::line() does only seem to accept object<Illuminate\Notifications\Action>|string, 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...
42
            ->attachData($this->buildException($this->event->exception),
43
                'failed_job_' . Carbon::now()->format('Y-m-d h:i:s') . '.txt')
44
            ->attachData($this->event->job->getRawBody(),
45
                'payload_' . Carbon::now()->format('Y-m-d h:i:s') . '.txt');
46
    }
47
48
    /**
49
     * Get the Slack representation of the notification.
50
     *
51
     * @param  mixed $notifiable
52
     * @return \Illuminate\Notifications\Messages\SlackMessage
53
     */
54
    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...
55
    {
56
        return (new SlackMessage)
57
            ->error()
58
            ->content(trans('laravel-failed-job-monitor::slack.intro'))
0 ignored issues
show
Bug introduced by
It seems like trans('laravel-failed-job-monitor::slack.intro') targeting trans() can also be of type object<Symfony\Component...on\TranslatorInterface>; however, Illuminate\Notifications...SlackMessage::content() does only seem to accept string, 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...
59
            ->attachment(function (SlackAttachment $attachment) {
60
                $attachment->title(trans('laravel-failed-job-monitor::slack.job_info'))
0 ignored issues
show
Bug introduced by
It seems like trans('laravel-failed-jo...nitor::slack.job_info') targeting trans() can also be of type object<Symfony\Component...on\TranslatorInterface>; however, Illuminate\Notifications...lackAttachment::title() does only seem to accept string, 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...
61
                    ->content($this->event->job->resolveName());
62
            })->attachment(function (SlackAttachment $attachment) {
63
                $attachment->title('failed_job_' . Carbon::now()->format('Y-m-d h:i:s') . '.txt')
64
                    ->content($this->buildException($this->event->exception));
65
            })->attachment(function (SlackAttachment $attachment) {
66
                $attachment->title('payload_' . Carbon::now()->format('Y-m-d h:i:s') . '.txt')
67
                    ->content($this->event->job->getRawBody());
68
            });
69
    }
70
71
    protected function buildException(\Exception $exception)
72
    {
73
        $response = sprintf(
74
            '%s: %s (%s:%s)',
75
            get_class($exception),
76
            $exception->getMessage(),
77
            $exception->getFile(),
78
            $exception->getLine()
79
        );
80
81
        $response .= PHP_EOL;
82
        $response .= $exception->getTraceAsString() . PHP_EOL;
83
84
        return $response;
85
    }
86
}
87