Passed
Pull Request — master (#36)
by Key
04:34
created

NewDevice::toNexmo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
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\Notification;
9
use Illuminate\Support\Carbon;
10
use Yadahan\AuthenticationLog\AuthenticationLog;
11
12
class NewDevice extends Notification implements ShouldQueue
13
{
14
    use Queueable;
15
16
    /**
17
     * The authentication log.
18
     */
19
    public AuthenticationLog $authenticationLog;
20
21
    /**
22
     * Create a new notification instance.
23
     *
24
     * @param AuthenticationLog $authenticationLog
25
     * @return void
26
     */
27
    public function __construct(AuthenticationLog $authenticationLog)
28
    {
29
        $this->authenticationLog = $authenticationLog;
30
    }
31
32
    /**
33
     * Get the notification's delivery channels.
34
     *
35
     * @param  mixed  $notifiable
36
     */
37
    public function via($notifiable): array
38
    {
39
        return $notifiable->notifyAuthenticationLogVia();
40
    }
41
42
    /**
43
     * Get the mail representation of the notification.
44
     *
45
     * @param  mixed  $notifiable
46
     */
47
    public function toMail($notifiable): MailMessage
48
    {
49
        /** @var Carbon $loginAt */
50
        $loginAt = $this->authenticationLog->login_at;
51
        $loginAt = $loginAt->setTimezone('UTC');
52
        return (new MailMessage)
53
            ->subject(trans('authentication-log::new_device.subject', ['app' => config('app.name')]))
0 ignored issues
show
Bug introduced by
It seems like trans('authentication-lo...=> config('app.name'))) can also be of type array and array; however, parameter $subject of Illuminate\Notifications...impleMessage::subject() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

53
            ->subject(/** @scrutinizer ignore-type */ trans('authentication-log::new_device.subject', ['app' => config('app.name')]))
Loading history...
54
            ->markdown('authentication-log::emails.new_device', [
55
                'account' => $notifiable,
56
                'loginAt' => $loginAt . ' UTC',
57
                'ipAddress' => $this->authenticationLog->ip_address,
58
                'browser' => $this->authenticationLog->user_agent,
59
            ])
60
            ;
61
    }
62
}
63