Passed
Push — master ( 3e77af...7c612c )
by Brian
02:49
created

VerifyEmail   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 22
dl 0
loc 101
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A createUrlUsing() 0 3 1
A toMailUsing() 0 3 1
A toMail() 0 9 2
A verificationUrl() 0 12 2
A buildMailMessage() 0 7 1
A via() 0 3 1
1
<?php
2
3
namespace App\Modules\Admins\Notifications\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
/**
13
 * @see \Illuminate\Auth\Notifications\VerifyEmail
14
 */
15
class VerifyEmail extends Notification
16
{
17
    /**
18
     * The callback that should be used to create the verify email URL.
19
     *
20
     * @var \Closure|null
21
     */
22
    public static $createUrlCallback;
23
24
    /**
25
     * The callback that should be used to build the mail message.
26
     *
27
     * @var \Closure|null
28
     */
29
    public static $toMailCallback;
30
31
    /**
32
     * Get the notification's channels.
33
     *
34
     * @param  mixed  $notifiable
35
     * @return array|string
36
     */
37
    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

37
    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...
38
    {
39
        return ['mail'];
40
    }
41
42
    /**
43
     * Build the mail representation of the notification.
44
     *
45
     * @param  mixed  $notifiable
46
     * @return \Illuminate\Notifications\Messages\MailMessage
47
     */
48
    public function toMail($notifiable)
49
    {
50
        $verificationUrl = $this->verificationUrl($notifiable);
51
52
        if (static::$toMailCallback) {
53
            return call_user_func(static::$toMailCallback, $notifiable, $verificationUrl);
54
        }
55
56
        return $this->buildMailMessage($verificationUrl);
57
    }
58
59
    /**
60
     * Get the verify email notification mail message for the given URL.
61
     *
62
     * @param  string  $url
63
     * @return \Illuminate\Notifications\Messages\MailMessage
64
     */
65
    protected function buildMailMessage($url)
66
    {
67
        return (new MailMessage)
68
            ->subject(Lang::get('Verify Email Address'))
0 ignored issues
show
Bug introduced by
It seems like Illuminate\Support\Facad...'Verify Email Address') can also be of type 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

68
            ->subject(/** @scrutinizer ignore-type */ Lang::get('Verify Email Address'))
Loading history...
69
            ->line(Lang::get('Please click the button below to verify your email address.'))
70
            ->action(Lang::get('Verify Email Address'), $url)
0 ignored issues
show
Bug introduced by
It seems like Illuminate\Support\Facad...'Verify Email Address') can also be of type array; however, parameter $text of Illuminate\Notifications...SimpleMessage::action() 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

70
            ->action(/** @scrutinizer ignore-type */ Lang::get('Verify Email Address'), $url)
Loading history...
71
            ->line(Lang::get('If you did not create an account, no further action is required.'));
72
    }
73
74
    /**
75
     * Get the verification URL for the given notifiable.
76
     *
77
     * @param  mixed  $notifiable
78
     * @return string
79
     */
80
    protected function verificationUrl($notifiable)
81
    {
82
        if (static::$createUrlCallback) {
83
            return call_user_func(static::$createUrlCallback, $notifiable);
84
        }
85
86
        return URL::temporarySignedRoute(
87
            'admin.verification.verify',
88
            Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)),
89
            [
90
                'id' => $notifiable->getKey(),
91
                'hash' => sha1($notifiable->getEmailForVerification()),
92
            ]
93
        );
94
    }
95
96
    /**
97
     * Set a callback that should be used when creating the email verification URL.
98
     *
99
     * @param  \Closure  $callback
100
     * @return void
101
     */
102
    public static function createUrlUsing($callback)
103
    {
104
        static::$createUrlCallback = $callback;
105
    }
106
107
    /**
108
     * Set a callback that should be used when building the notification mail message.
109
     *
110
     * @param  \Closure  $callback
111
     * @return void
112
     */
113
    public static function toMailUsing($callback)
114
    {
115
        static::$toMailCallback = $callback;
116
    }
117
}
118