GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

WelcomeNotification::toMailUsing()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Spatie\WelcomeNotification;
4
5
use Carbon\Carbon;
6
use Illuminate\Foundation\Auth\User;
7
use Illuminate\Notifications\Messages\MailMessage;
8
use Illuminate\Notifications\Notification;
9
use Illuminate\Support\Facades\Lang;
10
use Illuminate\Support\Facades\URL;
11
12
class WelcomeNotification extends Notification
13
{
14
    /** @var \Illuminate\Foundation\Auth\User */
15
    public $user;
16
17
    /** @var string */
18
    public $showWelcomeFormUrl;
19
20
    /** @var \Closure|null */
21
    public static $toMailCallback;
22
23
    /** @var \Carbon\Carbon */
24
    public $validUntil;
25
26
    public function __construct(Carbon $validUntil)
27
    {
28
        $this->validUntil = $validUntil;
29
    }
30
31
    public function via($notifiable)
0 ignored issues
show
Unused Code introduced by
The parameter $notifiable is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
32
    {
33
        return ['mail'];
34
    }
35
36
    public function toMail($notifiable)
37
    {
38
        $this->initializeNotificationProperties($notifiable);
39
40
        if (static::$toMailCallback) {
41
            return call_user_func(static::$toMailCallback, $notifiable);
42
        }
43
44
        return $this->buildWelcomeNotificationMessage();
45
    }
46
47
    protected function buildWelcomeNotificationMessage(): MailMessage
48
    {
49
        return (new MailMessage)
50
            ->subject(Lang::get('Welcome'))
51
            ->line(Lang::get('You are receiving this email because an account was created for you.'))
52
            ->action(Lang::get('Set initial password'), $this->showWelcomeFormUrl)
53
            ->line(Lang::get('This welcome link will expire in :count minutes.', ['count' => $this->validUntil->diffInRealMinutes()]));
54
    }
55
56
    public static function toMailUsing($callback)
57
    {
58
        static::$toMailCallback = $callback;
59
    }
60
61
    protected function initializeNotificationProperties(User $user)
62
    {
63
        $this->user = $user;
64
65
        $this->user->welcome_valid_until = $this->validUntil;
66
        $this->user->save();
67
68
        $this->showWelcomeFormUrl = URL::temporarySignedRoute(
69
            'welcome',
70
            $this->validUntil,
71
            ['user' => $user->id]
72
        );
73
    }
74
}
75