NewDevice::toSlack()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 1
dl 0
loc 12
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace serwin35\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 serwin35\AuthenticationLog\AuthenticationLog;
12
13
class NewDevice extends Notification implements ShouldQueue
14
{
15
    use Queueable;
16
17
    /**
18
     * The authentication log.
19
     *
20
     * @var \serwin35\AuthenticationLog\AuthenticationLog
21
     */
22
    public $authenticationLog;
23
24
    /**
25
     * Create a new notification instance.
26
     *
27
     * @param  \serwin35\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,
0 ignored issues
show
Bug introduced by
The property login_at does not seem to exist on serwin35\AuthenticationLog\AuthenticationLog. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
59
                'ipAddress' => $this->authenticationLog->ip_address,
0 ignored issues
show
Bug introduced by
The property ip_address does not seem to exist on serwin35\AuthenticationLog\AuthenticationLog. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
60
                'browser' => $this->authenticationLog->user_agent,
0 ignored issues
show
Bug introduced by
The property user_agent does not seem to exist on serwin35\AuthenticationLog\AuthenticationLog. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
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(),
0 ignored issues
show
Bug introduced by
The property login_at does not seem to exist on serwin35\AuthenticationLog\AuthenticationLog. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
80
                    'IP Address' => $this->authenticationLog->ip_address,
0 ignored issues
show
Bug introduced by
The property ip_address does not seem to exist on serwin35\AuthenticationLog\AuthenticationLog. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
81
                    'Browser' => $this->authenticationLog->user_agent,
0 ignored issues
show
Bug introduced by
The property user_agent does not seem to exist on serwin35\AuthenticationLog\AuthenticationLog. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
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
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(
96
                trans('authentication-log::messages.content', [
97
                    'app' => config('app.name')
98
                ])
99
            );
100
    }
101
}
102