Passed
Branch master (64a50e)
by Brian
02:57
created

VerifyEmail::via()   A

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 App\Notifications\Admin\Auth;
4
5
use Illuminate\Notifications\Messages\MailMessage;
6
use Illuminate\Notifications\Notification;
7
use Illuminate\Support\Carbon;
8
use Illuminate\Support\Facades\Config;
9
use Illuminate\Support\Facades\Lang;
10
use Illuminate\Support\Facades\URL;
11
12
class VerifyEmail extends Notification
13
{
14
    /**
15
     * The callback that should be used to build the mail message.
16
     *
17
     * @var null|\Closure
18
     */
19
    public static $toMailCallback;
20
21
    /**
22
     * Get the notification's channels.
23
     *
24
     * @param mixed $notifiable
25
     *
26
     * @return array|string
27
     */
28 1
    public function via($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

28
    public function via(/** @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...
29
    {
30 1
        return ['mail'];
31
    }
32
33
    /**
34
     * Build the mail representation of the notification.
35
     *
36
     * @param mixed $notifiable
37
     *
38
     * @return \Illuminate\Notifications\Messages\MailMessage
39
     */
40
    public function toMail($notifiable)
41
    {
42
        $verificationUrl = $this->verificationUrl($notifiable);
43
44
        if (static::$toMailCallback) {
45
            return \call_user_func(static::$toMailCallback, $notifiable, $verificationUrl);
46
        }
47
48
        return (new MailMessage())
49
            ->subject(Lang::get('Verify Email Address'))
50
            ->line(Lang::get('Please click the button below to verify your email address.'))
51
            ->action(Lang::get('Verify Email Address'), $verificationUrl)
52
            ->line(Lang::get('If you did not create an account, no further action is required.'))
53
        ;
54
    }
55
56
    /**
57
     * Set a callback that should be used when building the notification mail message.
58
     *
59
     * @param \Closure $callback
60
     */
61
    public static function toMailUsing($callback)
62
    {
63
        static::$toMailCallback = $callback;
64
    }
65
66
    /**
67
     * Get the verification URL for the given notifiable.
68
     *
69
     * @param mixed $notifiable
70
     *
71
     * @return string
72
     */
73
    protected function verificationUrl($notifiable)
74
    {
75
        return URL::temporarySignedRoute(
76
            'admin.verification.verify',
77
            Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)),
78
            [
79
                'id' => $notifiable->getKey(),
80
                'hash' => sha1($notifiable->getEmailForVerification()),
81
            ]
82
        );
83
    }
84
}
85