Completed
Push — master ( c0bd97...e686ed )
by Denis
06:32
created

anonymous//src/Listeners/NotifyUsers.php$0   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 18
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Akaunting\Firewall\Listeners;
4
5
use Akaunting\Firewall\Events\AttackDetected as Event;
6
use Akaunting\Firewall\Notifications\AttackDetected as Notification;
7
use Exception;
8
use GuzzleHttp\Exception\RequestException;
9
use Illuminate\Notifications\Notifiable;
10
use Throwable;
11
12
class NotifyUsers
13
{
14
    /**
15
     * Handle the event.
16
     *
17
     * @param Event $event
18
     *
19
     * @return void
20
     */
21
    public function handle(Event $event)
22
    {
23
        $notifiable = $this->getNotifiableClass();
24
25
        try {
26
            $notifiable->notify(new Notification($event->log));
27
        } catch (Exception | RequestException | Throwable $e) {
0 ignored issues
show
Bug introduced by Denis Duliçi
The class Throwable does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
28
            report($e);
29
        }
30
    }
31
32
    protected function getNotifiableClass()
33
    {
34
        return new class() {
35
            use Notifiable;
36
37
            public function routeNotificationForMail()
38
            {
39
                return config('firewall.notifications.mail.to');
40
            }
41
42
            public function routeNotificationForSlack()
43
            {
44
                return config('firewall.notifications.slack.to');
45
            }
46
47
            public function getKey()
48
            {
49
                return 1;
50
            }
51
        };
52
    }
53
}
54