NewDevice   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 24
c 4
b 0
f 0
dl 0
loc 83
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A toNexmo() 0 4 1
A via() 0 3 1
A toMail() 0 9 1
A toSlack() 0 12 1
1
<?php
2
3
namespace Yadahan\AuthenticationLog\Notifications;
4
5
use Illuminate\Bus\Queueable;
6
use Illuminate\Contracts\Queue\ShouldQueue;
7
use Illuminate\Notifications\Messages\MailMessage;
8
use Illuminate\Notifications\Messages\NexmoMessage;
9
use Illuminate\Notifications\Messages\SlackMessage;
10
use Illuminate\Notifications\Notification;
11
use Yadahan\AuthenticationLog\AuthenticationLog;
12
13
class NewDevice extends Notification implements ShouldQueue
14
{
15
    use Queueable;
16
17
    /**
18
     * The authentication log.
19
     *
20
     * @var \Yadahan\AuthenticationLog\AuthenticationLog
21
     */
22
    public $authenticationLog;
23
24
    /**
25
     * Create a new notification instance.
26
     *
27
     * @param  \Yadahan\AuthenticationLog\AuthenticationLog  $authenticationLog
28
     * @return void
29
     */
30
    public function __construct(AuthenticationLog $authenticationLog)
31
    {
32
        $this->authenticationLog = $authenticationLog;
33
    }
34
35
    /**
36
     * Get the notification's delivery channels.
37
     *
38
     * @param  mixed  $notifiable
39
     * @return array
40
     */
41
    public function via($notifiable)
42
    {
43
        return $notifiable->notifyAuthenticationLogVia();
44
    }
45
46
    /**
47
     * Get the mail representation of the notification.
48
     *
49
     * @param  mixed  $notifiable
50
     * @return \Illuminate\Notifications\Messages\MailMessage
51
     */
52
    public function toMail($notifiable)
53
    {
54
        return (new MailMessage)
55
            ->subject(trans('authentication-log::messages.subject'))
56
            ->markdown('authentication-log::emails.new', [
57
                'account' => $notifiable,
58
                'time' => $this->authenticationLog->login_at,
59
                'ipAddress' => $this->authenticationLog->ip_address,
60
                'browser' => $this->authenticationLog->user_agent,
61
            ]);
62
    }
63
64
    /**
65
     * Get the Slack representation of the notification.
66
     *
67
     * @param  mixed  $notifiable
68
     * @return \Illuminate\Notifications\Messages\SlackMessage
69
     */
70
    public function toSlack($notifiable)
71
    {
72
        return (new SlackMessage)
73
            ->from(config('app.name'))
74
            ->warning()
75
            ->content(trans('authentication-log::messages.content', ['app' => config('app.name')]))
76
            ->attachment(function ($attachment) use ($notifiable) {
77
                $attachment->fields([
78
                    'Account' => $notifiable->email,
79
                    'Time' => $this->authenticationLog->login_at->toCookieString(),
80
                    'IP Address' => $this->authenticationLog->ip_address,
81
                    'Browser' => $this->authenticationLog->user_agent,
82
                ]);
83
            });
84
    }
85
86
    /**
87
     * Get the Nexmo / SMS representation of the notification.
88
     *
89
     * @param  mixed  $notifiable
90
     * @return \Illuminate\Notifications\Messages\NexmoMessage
91
     */
92
    public function toNexmo($notifiable)
0 ignored issues
show
Unused Code introduced by Yaakov Dahan
The parameter $notifiable is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

92
    public function toNexmo(/** @scrutinizer ignore-unused */ $notifiable)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
93
    {
94
        return (new NexmoMessage)
95
            ->content(trans('authentication-log::messages.content', ['app' => config('app.name')]));
96
    }
97
}
98