ResetPasswordNotification::via()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace  Devpri\Tinre\Notifications;
4
5
use Illuminate\Notifications\Messages\MailMessage;
6
use Illuminate\Notifications\Notification;
7
use Illuminate\Support\Facades\Lang;
8
9
class ResetPasswordNotification extends Notification
10
{
11
    /**
12
     * The password reset token.
13
     *
14
     * @var string
15
     */
16
    public $token;
17
18
    /**
19
     * The callback that should be used to create the reset password URL.
20
     *
21
     * @var \Closure|null
22
     */
23
    public static $createUrlCallback;
24
25
    /**
26
     * The callback that should be used to build the mail message.
27
     *
28
     * @var \Closure|null
29
     */
30
    public static $toMailCallback;
31
32
    /**
33
     * Create a notification instance.
34
     *
35
     * @param  string  $token
36
     * @return void
37
     */
38 1
    public function __construct($token)
39
    {
40 1
        $this->token = $token;
41 1
    }
42
43
    /**
44
     * Get the notification's channels.
45
     *
46
     * @param  mixed  $notifiable
47
     * @return array|string
48
     */
49 1
    public function via($notifiable)
50
    {
51 1
        return ['mail'];
52
    }
53
54
    /**
55
     * Build the mail representation of the notification.
56
     *
57
     * @param  mixed  $notifiable
58
     * @return \Illuminate\Notifications\Messages\MailMessage
59
     */
60
    public function toMail($notifiable)
61
    {
62
        if (static::$toMailCallback) {
63
            return call_user_func(static::$toMailCallback, $notifiable, $this->token);
64
        }
65
66
        if (static::$createUrlCallback) {
67
            $url = call_user_func(static::$createUrlCallback, $notifiable, $this->token);
68
        } else {
69
            $url = url(route('password.reset', [
70
                'token' => $this->token,
71
                'email' => $notifiable->getEmailForPasswordReset(),
72
            ], false));
73
        }
74
75
        return (new MailMessage)
76
            ->subject(Lang::get('Reset Password Notification'))
77
            ->line(Lang::get('You are receiving this email because we received a password reset request for your account.'))
78
            ->action(Lang::get('Reset Password'), $url)
79
            ->line(Lang::get('This password reset link will expire in :count minutes.', ['count' => config('auth.passwords.'.config('auth.defaults.passwords').'.expire')]))
80
            ->line(Lang::get('If you did not request a password reset, no further action is required.'));
81
    }
82
83
    /**
84
     * Set a callback that should be used when creating the reset password button URL.
85
     *
86
     * @param  \Closure  $callback
87
     * @return void
88
     */
89
    public static function createUrlUsing($callback)
90
    {
91
        static::$createUrlCallback = $callback;
92
    }
93
94
    /**
95
     * Set a callback that should be used when building the notification mail message.
96
     *
97
     * @param  \Closure  $callback
98
     * @return void
99
     */
100
    public static function toMailUsing($callback)
101
    {
102
        static::$toMailCallback = $callback;
103
    }
104
}
105