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.
Completed
Push — master ( e68406...5eb45b )
by Freek
07:33
created

buildWelcomeNotificationMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\Password;
11
use Illuminate\Support\Facades\URL;
12
13
class WelcomeNotification extends Notification
14
{
15
    /** @var \Illuminate\Foundation\Auth\User */
16
    public $user;
17
18
    /** @var string */
19
    public $showWelcomeFormUrl;
20
21
    /** @var \Closure|null */
22
    public static $toMailCallback;
23
24
    /** @var \Carbon\Carbon */
25
    public $validUntil;
26
27
    public function __construct(Carbon $validUntil)
28
    {
29
        $this->validUntil = $validUntil;
30
    }
31
32
    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...
33
    {
34
        return ['mail'];
35
    }
36
37
    public function toMail($notifiable)
38
    {
39
        $this->initializeNotificationProperties($notifiable);
40
41
        if (static::$toMailCallback) {
42
            return call_user_func(static::$toMailCallback, $notifiable, $this->token);
0 ignored issues
show
Bug introduced by
The property token does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
43
        }
44
45
        return $this->buildWelcomeNotificationMessage();
46
    }
47
48
    protected function buildWelcomeNotificationMessage(): MailMessage
49
    {
50
        return (new MailMessage)
51
            ->subject(Lang::get('Welcome'))
52
            ->line(Lang::get('You are receiving this email an account for you was created.'))
53
            ->action(Lang::get('Set initial password'), $this->showWelcomeFormUrl)
54
            ->line(Lang::get('This welcome link will expire in :count minutes.', ['count' => config('auth.passwords.'.config('auth.defaults.passwords').'.expire')]));
55
    }
56
57
    public static function toMailUsing($callback)
58
    {
59
        static::$toMailCallback = $callback;
60
    }
61
62
    protected function initializeNotificationProperties(User $user)
63
    {
64
        $this->user = $user;
65
66
        $this->user->welcome_valid_until = $this->validUntil;
67
        $this->user->save();
68
69
        $this->showWelcomeFormUrl = URL::temporarySignedRoute(
70
            'welcome', $this->validUntil, ['user' => $user->id]
71
        );
72
    }
73
}
74