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.

FailedJobNotifier   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 85%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 43
ccs 17
cts 20
cp 0.85
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 TalvBansal\ThrottledFailedJobMonitor;
4
5
use Illuminate\Queue\Events\JobFailed;
6
use Illuminate\Queue\QueueManager;
7
use TalvBansal\ThrottledFailedJobMonitor\Exceptions\InvalidConfiguration;
8
9
class FailedJobNotifier
10
{
11 5
    public function register()
12
    {
13
        app(QueueManager::class)->failing(function (JobFailed $event) {
14 5
            $notifiable = app(config('throttled-failed-jobs.notifiable'));
15
16 5
            $notification = app(config('throttled-failed-jobs.notification'))->setEvent($event);
17
18 5
            if (! $this->isValidNotificationClass($notification)) {
19
                throw InvalidConfiguration::notificationClassInvalid(get_class($notification));
20
            }
21
22 5
            if ($this->shouldSendNotification($notification)) {
23 5
                $notifiable->notify($notification);
24
            }
25 5
        });
26 5
    }
27
28 5
    public function isValidNotificationClass($notification): bool
29
    {
30 5
        if (get_class($notification) === Notification::class) {
31 4
            return true;
32
        }
33
34 1
        if (is_subclass_of($notification, Notification::class)) {
35 1
            return true;
36
        }
37
38
        return false;
39
    }
40
41 5
    public function shouldSendNotification($notification)
42
    {
43 5
        $callable = config('throttled-failed-jobs.notificationFilter');
44
45 5
        if (! is_callable($callable)) {
46 5
            return true;
47
        }
48
49
        return $callable($notification);
50
    }
51
}
52