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 ( 0a6959...4adca0 )
by Pascal
01:06
created

resendPendingEmailVerificationMail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace ProtoneMedia\LaravelVerifyNewEmail;
4
5
use Illuminate\Support\Facades\Mail;
6
use Illuminate\Support\Facades\Password;
7
use ProtoneMedia\LaravelVerifyNewEmail\Mail\VerifyNewEmail;
8
9
trait MustVerifyNewEmail
10
{
11
    /**
12
     * Deletes all previous attempts for this user, creates a new model/token
13
     * to verify the given email address and send the verification URL
14
     * to the new email address.
15
     *
16
     * @param string $email
17
     * @return \ProtoneMedia\LaravelVerifyNewEmail\PendingUserEmail|null
18
     */
19
    public function newEmail(string $email):?PendingUserEmail
20
    {
21
        $this->clearPendingEmail();
22
23
        if ($this->email === $email) {
0 ignored issues
show
Bug introduced by
The property email 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...
24
            return null;
25
        }
26
27
        return tap(PendingUserEmail::create([
28
            'user_type' => get_class($this),
29
            'user_id'   => $this->getKey(),
0 ignored issues
show
Bug introduced by
It seems like getKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
30
            'email'     => $email,
31
            'token'     => Password::broker()->getRepository()->createNewToken(),
32
        ]), function ($pendingUserEmail) {
33
            $this->sendPendingEmailVerificationMail($pendingUserEmail);
34
        });
35
    }
36
37
    /**
38
     * Returns the pending email address.
39
     *
40
     * @return string|null
41
     */
42
    public function getPendingEmail():?string
43
    {
44
        return PendingUserEmail::forUser($this)->value('email');
45
    }
46
47
    /**
48
     * Deletes the pending email address models for this user.
49
     *
50
     * @return void
51
     */
52
    public function clearPendingEmail()
53
    {
54
        PendingUserEmail::forUser($this)->get()->each->delete();
55
    }
56
57
    /**
58
     * Sends the VerifyNewEmail Mailable to the new email address.
59
     *
60
     * @param \ProtoneMedia\LaravelVerifyNewEmail\PendingUserEmail $pendingUserEmail
61
     * @return mixed
62
     */
63
    public function sendPendingEmailVerificationMail(PendingUserEmail $pendingUserEmail)
64
    {
65
        return Mail::to($pendingUserEmail->email)->send(new VerifyNewEmail($pendingUserEmail));
66
    }
67
68
    /**
69
     * Grabs the pending user email address, generates a new token and sends the Mailable.
70
     *
71
     * @return \ProtoneMedia\LaravelVerifyNewEmail\PendingUserEmail|null
72
     */
73
    public function resendPendingEmailVerificationMail():?PendingUserEmail
74
    {
75
        $pendingUserEmail = PendingUserEmail::forUser($this)->firstOrFail();
76
77
        return $this->newEmail($pendingUserEmail->email);
78
    }
79
}
80