Completed
Pull Request — master (#1)
by Artem
03:18
created

UserHelpers   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 108
rs 10
c 0
b 0
f 0
wmc 12

11 Methods

Rating   Name   Duplication   Size   Complexity  
A retrieveName() 0 3 1
A retrieveUpdatedAt() 0 3 1
A retrievePassword() 0 3 1
A retrieveEmail() 0 3 1
A retrieveId() 0 3 1
A retrieveRemoteId() 0 3 1
A retrieveCreatedAt() 0 3 1
A retrieveDeletedAt() 0 3 1
A sendPasswordResetNotification() 0 3 1
A deleteEmail() 0 7 2
A restoreEmail() 0 3 1
1
<?php
2
3
namespace Slides\Connector\Auth\Concerns;
4
5
use Slides\Connector\Auth\Notifications\ResetPasswordNotification;
6
use Illuminate\Auth\Passwords\CanResetPassword;
7
8
/**
9
 * Trait UserHelpers
10
 *
11
 * @package Slides\Connector\Auth\Concerns
12
 */
13
trait UserHelpers
14
{
15
    use CanResetPassword;
16
17
    /**
18
     * @inheritdoc
19
     */
20
    public function retrieveId()
21
    {
22
        return $this->id;
23
    }
24
25
    /**
26
     * @inheritdoc
27
     */
28
    public function retrieveRemoteId()
29
    {
30
        return $this->remote_id;
31
    }
32
33
    /**
34
     * @inheritdoc
35
     */
36
    public function retrieveName()
37
    {
38
        return $this->name;
39
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44
    public function retrieveEmail()
45
    {
46
        return $this->email;
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52
    public function retrievePassword()
53
    {
54
        return $this->password;
55
    }
56
57
    /**
58
     * @inheritdoc
59
     */
60
    public function retrieveCreatedAt()
61
    {
62
        return $this->created_at;
63
    }
64
65
    /**
66
     * @inheritdoc
67
     */
68
    public function retrieveUpdatedAt()
69
    {
70
        return $this->updated_at;
71
    }
72
73
    /**
74
     * @inheritdoc
75
     */
76
    public function retrieveDeletedAt()
77
    {
78
        return $this->getDeletedAtColumn();
0 ignored issues
show
Bug introduced by
It seems like getDeletedAtColumn() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

78
        return $this->/** @scrutinizer ignore-call */ getDeletedAtColumn();
Loading history...
79
    }
80
81
    /**
82
     * Send the password reset notification.
83
     *
84
     * @param string $token
85
     *
86
     * @return void
87
     */
88
    public function sendPasswordResetNotification($token)
89
    {
90
        $this->notify(new ResetPasswordNotification($token));
0 ignored issues
show
Bug introduced by
It seems like notify() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

90
        $this->/** @scrutinizer ignore-call */ 
91
               notify(new ResetPasswordNotification($token));
Loading history...
91
    }
92
93
    /**
94
     * Transform user's email to "deleted email".
95
     *
96
     * @param string $email
97
     * @param int $index
98
     *
99
     * @return string
100
     */
101
    public static function deleteEmail(string $email, int $index): string
102
    {
103
        if(strpos($email, ".{$index}.deleted" !== false)) {
104
            return $email;
105
        }
106
107
        return "{$email}.{$index}.deleted";
108
    }
109
110
    /**
111
     * Transform user's "deleted email" to an original one.
112
     *
113
     * @param string $email
114
     * @param int $index
115
     *
116
     * @return string
117
     */
118
    public static function restoreEmail(string $email, int $index): string
119
    {
120
        return str_replace(".{$index}.deleted", '', $email);
121
    }
122
}