EmailVerificationNotification   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 84.21%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 68
ccs 16
cts 19
cp 0.8421
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toMailUsing() 0 3 1
A verificationUrl() 0 8 1
A via() 0 3 1
A toMail() 0 13 2
1
<?php
2
3
namespace Devpri\Tinre\Notifications;
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 EmailVerificationNotification extends Notification
13
{
14
    /**
15
     * The callback that should be used to build the mail message.
16
     *
17
     * @var \Closure|null
18
     */
19
    public static $toMailCallback;
20
21
    /**
22
     * Get the notification's channels.
23
     *
24
     * @param  mixed  $notifiable
25
     * @return array|string
26
     */
27 2
    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

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