Completed
Pull Request — master (#78)
by Brandon
02:00
created

User   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 136
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 7
c 2
b 0
f 1
lcom 0
cbo 4
dl 0
loc 136
ccs 0
cts 15
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isGuest() 0 4 1
A managers() 0 4 1
A routeNotificationForNexmo() 0 4 1
A roleString() 0 5 1
1
<?php
2
3
namespace App;
4
5
use Illuminate\Notifications\Notifiable;
6
use Illuminate\Foundation\Auth\User as Authenticatable;
7
use Illuminate\Database\Eloquent\SoftDeletes;
8
use Spatie\Activitylog\Traits\LogsActivity;
9
//use Spatie\Activitylog\Traits\CausesActivity;
10
11
class User extends Authenticatable
12
{
13
    use Notifiable;
14
    use SoftDeletes;
15
    use LogsActivity;
16
    //use CausesActivity;
17
18
    /**
19
     * The attributes that should be mutated to dates.
20
     *
21
     * @var array
22
     */
23
    protected $dates = [
24
        'deleted_at'
25
    ];
26
27
    /**
28
     * The attributes that are mass assignable.
29
     *
30
     * @var array
31
     */
32
    protected $fillable = [
33
        'name', 'email', 'password', 'role', 'phone'
34
    ];
35
    
36
    /**
37
     * The attributes to ignore in the Activity Log
38
     *
39
     * @var array
40
     */
41
    protected static $ignoreChangedAttributes = ['updated_at'];
42
    
43
    /**
44
     * The attributes to log in the Activity Log
45
     *
46
     * @var array
47
     */
48
    protected static $logAttributes = [
49
        'name', 'email', 'password', 'role', 'phone'
50
    ];
51
    
52
    /**
53
     * Only log those that have actually changed after the update.
54
     *
55
     * @var array
56
     */
57
    protected static $logOnlyDirty = true;
58
59
    /**
60
     * The attributes that should be hidden for arrays.
61
     *
62
     * @var array
63
     */
64
    protected $hidden = [
65
        'password', 'remember_token',
66
    ];
67
    
68
    /**
69
     * Update the updated_at and created_at timestamps?
70
     *
71
     * @var array
72
     */
73
    public $timestamps = true;
74
75
    /**
76
     * Route notifications for the Nexmo channel.
77
     *
78
     * @return string
79
     */
80
    public function routeNotificationForNexmo()
81
    {
82
        return $this->phone;
83
    }
84
    
85
    /**
86
     * Is user Admin or better?
87
     *
88
     * @return boolean
89
     */
90
    public function isAdmin()
91
    {
92
        return $this->role > 2;
93
    }
94
    
95
    /**
96
     * Is user Manager or better?
97
     *
98
     * @return boolean
99
     */
100
    public function isManager()
101
    {
102
        return $this->role > 1;
103
    }
104
105
    /**
106
     * Is user User or better?
107
     *
108
     * @return boolean
109
     */
110
    public function isUser()
111
    {
112
        return $this->role > 0;
113
    }
114
    
115
    /**
116
     * Is user a guest?
117
     *
118
     * @return boolean
119
     */
120
    public function isGuest()
121
    {
122
        return $this->role == 0;
123
    }
124
    
125
    
126
    /**
127
     * Returns a list of managers.
128
     *
129
     * @return Users
130
     */
131
    public function managers()
132
    {
133
        return $this->where('role', '>', 1)->get();
134
    }
135
    
136
    /**
137
     * Returns the users role as a string.
138
     *
139
     * @return Users
140
     */
141
    public function roleString()
142
    {
143
        $role_en = array(0 => "Registered", 1 => "User", 2 => "Manager", 3 => "Admin");
144
        return $role_en[ $this->role ] . ' (' . $this->role . ')';
145
    }
146
}
147