Passed
Push — master ( 84c77a...d6297e )
by Yaakov
03:36
created

src/Notifications/NewDevice.php (1 issue)

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

91
    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...
92
    {
93
        return (new NexmoMessage)
94
            ->content(trans('authentication-log::messages.content', ['app' => config('app.name')]));
95
    }
96
}
97