Completed
Push — master ( 210c8c...df73be )
by ARCANEDEV
04:38
created

User::isMember()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 2
cp 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php namespace Arcanesoft\Auth\Models;
2
3
use Arcanedev\LaravelAuth\Models\User as BaseUserModel;
4
use Arcanedev\LaravelImpersonator\Contracts\Impersonatable;
5
use Arcanedev\LaravelImpersonator\Traits\CanImpersonate;
6
7
/**
8
 * Class     User
9
 *
10
 * @package  Arcanesoft\Auth\Models
11
 * @author   ARCANEDEV <[email protected]>
12
 *
13
 * @property  \Arcanesoft\Auth\Models\PasswordReset  passwordReset
14
 */
15
class User extends BaseUserModel implements Impersonatable
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: can, forceDelete, forceFill, getAuthIdentifier, getAuthIdentifierName, getAuthPassword, getEmailForPasswordReset, getKey, getRememberToken, getRememberTokenName, isForceDeleting, restore, sendPasswordResetNotification, setAttribute, setRememberToken, trashed
Loading history...
16
{
17
    /* -----------------------------------------------------------------
18
     |  Traits
19
     | -----------------------------------------------------------------
20
     */
21
22
    use Presenters\UserPresenter,
23
        CanImpersonate;
24
25
    /* -----------------------------------------------------------------
26
     |  Relationships
27
     | -----------------------------------------------------------------
28
     */
29
30
    /**
31
     * Password reset relationship.
32
     *
33
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
34
     */
35
    public function passwordReset()
36
    {
37
        return $this->hasOne(PasswordReset::class, 'email', 'email');
38
    }
39
40
    /* -----------------------------------------------------------------
41
     |  Main Methods
42
     | -----------------------------------------------------------------
43
     */
44
45
    /**
46
     * Get a user from a hashed id or fail if not found.
47
     *
48
     * @param  string  $hashedId
49
     *
50
     * @return self
51
     *
52
     * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
53
     */
54
    public static function firstHashedOrFail($hashedId)
55
    {
56
        return self::withTrashed()->withHashedId($hashedId)->firstOrFail();
57
    }
58
59
    /* -----------------------------------------------------------------
60
     |  Check Methods
61
     | -----------------------------------------------------------------
62
     */
63
64
    /**
65
     * Check if user is an administrator.
66
     *
67
     * @return bool
68
     */
69
    public function isAdmin()
70
    {
71
        return parent::isAdmin() || $this->hasRoleSlug(Role::ADMINISTRATOR);
72
    }
73
74
    /**
75
     * Check if user is a moderator.
76
     *
77
     * @return bool
78
     */
79
    public function isModerator()
80
    {
81
        return $this->hasRoleSlug(Role::MODERATOR);
82
    }
83
84
    /**
85
     * Check if user is a member.
86
     *
87
     * @return bool
88
     */
89
    public function isMember()
90
    {
91
        return $this->hasRoleSlug(Role::MEMBER);
92
    }
93
94
    /**
95
     * Check if user has a password reset.
96
     *
97
     * @return bool
98
     */
99
    public function hasPasswordReset()
100
    {
101
        return ! is_null($this->passwordReset);
102
    }
103
104
    /**
105
     * Check if the current modal can impersonate other models.
106
     *
107
     * @return  bool
108
     */
109
    public function canImpersonate()
110
    {
111
        return $this->isAdmin();
112
    }
113
114
    /**
115
     * Check if the current model can be impersonated.
116
     *
117
     * @return  bool
118
     */
119
    public function canBeImpersonated()
120
    {
121
        return ! $this->isAdmin();
122
    }
123
}
124