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 ( 03447e...d5a00d )
by Freek
06:53
created

FailedJobNotifier   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 43
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 16 3
A isValidNotificationClass() 0 12 3
A shouldSendNotification() 0 10 2
1
<?php
2
3
namespace Spatie\FailedJobMonitor;
4
5
use Illuminate\Queue\QueueManager;
6
use Illuminate\Queue\Events\JobFailed;
7
use Spatie\FailedJobMonitor\Exceptions\InvalidConfiguration;
8
9
class FailedJobNotifier
10
{
11
    public function register()
12
    {
13
        app(QueueManager::class)->failing(function (JobFailed $event) {
14
            $notifiable = app(config('laravel-failed-job-monitor.notifiable'));
15
16
            $notification = app(config('laravel-failed-job-monitor.notification'))->setEvent($event);
17
18
            if (! $this->isValidNotificationClass($notification)) {
19
                throw InvalidConfiguration::notificationClassInvalid(get_class($notification));
20
            }
21
22
            if ($this->shouldSendNotification($notification)) {
23
                $notifiable->notify($notification);
24
            }
25
        });
26
    }
27
28
    public function isValidNotificationClass($notification): bool
29
    {
30
        if (get_class($notification) === Notification::class) {
31
            return true;
32
        }
33
34
        if (is_subclass_of($notification, Notification::class)) {
35
            return true;
36
        }
37
38
        return false;
39
    }
40
41
    public function shouldSendNotification($notification)
42
    {
43
        $callable = config('laravel-failed-job-monitor.notificationFilter');
44
45
        if (! is_callable($callable)) {
46
            return true;
47
        }
48
49
        return $callable($notification);
50
    }
51
}
52