User   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 62
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A setNewPasswordAttribute() 0 4 2
1
<?php
2
3
namespace App;
4
5
use App\Traits\GravatarTrait;
6
use Illuminate\Foundation\Auth\User as Authenticatable;
7
use Illuminate\Notifications\Notifiable;
8
9
class User extends Authenticatable
10
{
11
    use Notifiable;
0 ignored issues
show
introduced by
The trait Illuminate\Notifications\Notifiable requires some properties which are not provided by App\User: $email, $phone_number
Loading history...
12
    use GravatarTrait;
0 ignored issues
show
introduced by
The trait App\Traits\GravatarTrait requires some properties which are not provided by App\User: $avatar, $email
Loading history...
13
14
    protected $table = 'users';
15
16
    /**
17
     * The attributes that are mass assignable.
18
     *
19
     * @var array
20
     */
21
    protected $fillable = [
22
        'name',
23
        'login',
24
        'role_id',
25
        'email',
26
        'password',
27
        'active',
28
    ];
29
30
    /**
31
     * The attributes that should be hidden for arrays.
32
     *
33
     * @var array
34
     */
35
    protected $hidden = [
36
        'active',
37
        'role_id',
38
        'password',
39
        'remember_token',
40
    ];
41
42
    /**
43
     * The attributes that should be cast to native types.
44
     *
45
     * @var array
46
     */
47
    protected $casts = [
48
      'email_verified_at' => 'datetime',
49
    ];
50
51
    public function isAdmin()
52
    {
53
        return $this->role_id == 3;
54
    }
55
56
    public function isModerator()
57
    {
58
        return $this->role_id == 2;
59
    }
60
61
    public function roles()
62
    {
63
        return $this->belongsTo(Role::class, 'role_id', 'id');
64
    }
65
66
    //admin password
67
    public function setNewPasswordAttribute($value)
68
    {
69
        if ($value) {
70
            $this->attributes['password'] = bcrypt($value);
71
        }
72
    }
73
}
74