Passed
Branch master (cd4548)
by Fèvre
19:36
created

VerifyEmail   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
dl 0
loc 73
rs 10
c 1
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A verificationUrl() 0 8 1
A toMailUsing() 0 3 1
A toMail() 0 16 2
A via() 0 3 1
1
<?php
2
namespace Xetaravel\Notifications\Auth;
3
4
use Illuminate\Bus\Queueable;
5
use Illuminate\Contracts\Queue\ShouldQueue;
6
use Illuminate\Notifications\Messages\MailMessage;
7
use Illuminate\Notifications\Notification;
8
use Illuminate\Support\Carbon;
9
use Illuminate\Support\Facades\Config;
10
use Illuminate\Support\Facades\Lang;
11
use Illuminate\Support\Facades\URL;
12
13
class VerifyEmail extends Notification implements ShouldQueue
14
{
15
    use Queueable;
16
17
    /**
18
     * The callback that should be used to build the mail message.
19
     *
20
     * @var \Closure|null
21
     */
22
    public static $toMailCallback;
23
24
    /**
25
     * Get the notification's channels.
26
     *
27
     * @param  mixed  $notifiable
28
     * @return array|string
29
     */
30
    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

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