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 ( 0941c5...11f95b )
by Freek
02:01
created

EventHandler::subscribe()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace Spatie\UptimeMonitor\Notifications;
4
5
use Illuminate\Config\Repository;
6
use Illuminate\Contracts\Events\Dispatcher;
7
use Illuminate\Notifications\Notification;
8
use Spatie\UptimeMonitor\Events\BackupHasFailed;
9
10
class EventHandler
11
{
12
    /** @var \Illuminate\Config\Repository */
13
    protected $config;
14
15
    public function __construct(Repository $config)
16
    {
17
        $this->config = $config;
18
    }
19
20
    public function subscribe(Dispatcher $events)
21
    {
22
        $events->listen($this->allBackupEventClasses(), function ($event) {
23
            $notifiable = $this->determineNotifiable();
24
25
            $notification = $this->determineNotification($event);
26
27
            $notifiable->notify($notification);
28
        });
29
    }
30
31
    protected function determineNotifiable()
32
    {
33
        $notifiableClass = $this->config->get('laravel-backup.notifications.notifiable');
34
35
        return app($notifiableClass);
36
    }
37
38
    protected function determineNotification($event): Notification
39
    {
40
        $eventName = class_basename($event);
41
42
        $notificationClass = collect($this->config->get('laravel-backup.notifications.notifications'))
43
            ->keys()
44
            ->first(function ($notificationClass) use ($eventName) {
45
                $notificationName = class_basename($notificationClass);
46
47
                return $notificationName === $eventName;
48
            });
49
50
        if (! $notificationClass) {
51
            throw NotificationCouldNotBeSent::noNotifcationClassForEvent($event);
52
        }
53
54
        return app($notificationClass)->setEvent($event);
55
    }
56
57
    protected function allBackupEventClasses(): array
58
    {
59
        return [
60
            BackupHasFailed::class,
61
        ];
62
    }
63
}
64