NotifyUsers::handle()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 4
nc 4
nop 1
1
<?php
2
3
namespace Spinzar\Firewall\Listeners;
4
5
use Spinzar\Firewall\Events\AttackDetected as Event;
6
use Spinzar\Firewall\Notifications\AttackDetected as Notification;
7
8
class NotifyUsers
9
{
10
    /**
11
     * Handle the event.
12
     *
13
     * @param Event $event
14
     *
15
     * @return void
16
     */
17
    public function handle(Event $event)
18
    {
19
        $model = config('firewall.models.user');
20
21
        if (!class_exists($model)) {
22
            return;
23
        }
24
25
        $emails = config('firewall.notifications.mail.to');
26
27
        foreach ($emails as $email) {
28
            $user = $model::where('email', $email)->first();
29
30
            if (empty($user)) {
31
                continue;
32
            }
33
34
            $user->notify(new Notification($event->log));
35
        }
36
    }
37
}
38