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 ( c6944f...11f4b5 )
by Freek
05:17
created

EventHandler::allUptimeMonitorEventClasses()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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