Completed
Push — master ( 8da79d...fd43b2 )
by ARCANEDEV
03:03
created

User::getFullNameAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
crap 6
1
<?php namespace Arcanesoft\Auth\Models;
2
3
use Arcanedev\LaravelAuth\Models\User as BaseUserModel;
4
5
/**
6
 * Class     User
7
 *
8
 * @package  Arcanesoft\Auth\Models
9
 * @author   ARCANEDEV <[email protected]>
10
 *
11
 * @property  string  gravatar
12
 */
13
class User extends BaseUserModel
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, getAuthIdentifier, getAuthIdentifierName, getAuthPassword, getEmailForPasswordReset, getRememberToken, getRememberTokenName, sendPasswordResetNotification, setAttribute, setRememberToken
Loading history...
14
{
15
    /* ------------------------------------------------------------------------------------------------
16
     |  Getters & Setters
17
     | ------------------------------------------------------------------------------------------------
18
     */
19
    /**
20
     * Get the user hash id.
21
     *
22
     * @return string
23
     */
24
    public function getHashedIdAttribute()
25
    {
26
        return self::hasher()->encode($this->id);
27
    }
28
29
    /**
30
     * Get the full name attribute or use the username if empty.
31
     *
32
     * @return string
33
     */
34
    public function getFullNameAttribute()
35
    {
36
        $fullName = trim("{$this->first_name} {$this->last_name}");
37
38
        return empty($fullName) ? $this->username : $fullName;
39
    }
40
41
    /**
42
     * Get the gravatar attribute.
43
     *
44
     * @return string
45
     */
46
    public function getGravatarAttribute()
47
    {
48
        return gravatar()
49
            ->setDefaultImage('mm')->setSize(160)
50
            ->src($this->email);
51
    }
52
53
    /**
54
     * Get the since date attribute (translated).
55
     *
56
     * @return string
57
     */
58
    public function getSinceDateAttribute()
59
    {
60
        return trans('auth::users.since', [
61
            'date' => $this->created_at->toFormattedDateString()
62
        ]);
63
    }
64
65
    /* ------------------------------------------------------------------------------------------------
66
     |  Main Function
67
     | ------------------------------------------------------------------------------------------------
68
     */
69
    /**
70
     * Get a user from a hashed id or fail if not found.
71
     *
72
     * @param  string  $hashedId
73
     *
74
     * @return self
75
     *
76
     * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
77
     */
78
    public static function firstHashedOrFail($hashedId)
79
    {
80
        $id = self::hasher()->decode($hashedId);
81
82
        return self::withTrashed()->where('id', $id)->firstOrFail();
83
    }
84
85
    /* ------------------------------------------------------------------------------------------------
86
     |  Check Functions
87
     | ------------------------------------------------------------------------------------------------
88
     */
89
    /**
90
     * Check if user is an administrator.
91
     *
92
     * @return bool
93
     */
94
    public function isAdmin()
95
    {
96
        return parent::isAdmin() || $this->hasRoleSlug(Role::ADMINISTRATOR);
97
    }
98
99
    /**
100
     * Check if user is a moderator.
101
     *
102
     * @return bool
103
     */
104
    public function isModerator()
105
    {
106
        return $this->hasRoleSlug(Role::MODERATOR);
107
    }
108
109
    /**
110
     * Check if user is a member.
111
     *
112
     * @return bool
113
     */
114
    public function isMember()
115
    {
116
        return $this->hasRoleSlug(Role::MEMBER);
117
    }
118
119
    /* ------------------------------------------------------------------------------------------------
120
     |  Other Functions
121
     | ------------------------------------------------------------------------------------------------
122
     */
123
    /**
124
     * Get the hasher.
125
     *
126
     * @return \Arcanedev\Hasher\Contracts\HashManager
127
     */
128
    protected static function hasher()
129
    {
130
        return hasher();
131
    }
132
}
133