Passed
Push — master ( 26caeb...0e28f7 )
by Thomas
11:18
created

User::sendPasswordResetNotification()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace App\Models;
4
5
use App\Events\UserDeleting;
6
use Backpack\CRUD\app\Models\Traits\CrudTrait;
7
use Illuminate\Database\Eloquent\SoftDeletes;
8
use Illuminate\Foundation\Auth\User as Authenticatable;
9
use Illuminate\Notifications\Notifiable;
10
use Illuminate\Support\Str;
11
use Spatie\Activitylog\Traits\LogsActivity;
12
use Spatie\Permission\Traits\HasRoles;
13
14
/**
15
 * @mixin IdeHelperUser
16
 */
17
class User extends Authenticatable
18
{
19
    use Notifiable;
0 ignored issues
show
Bug introduced by
The trait Illuminate\Notifications\Notifiable requires the property $email which is not provided by App\Models\User.
Loading history...
20
    use SoftDeletes;
21
    use CrudTrait;
0 ignored issues
show
introduced by
The trait Backpack\CRUD\app\Models\Traits\CrudTrait requires some properties which are not provided by App\Models\User: $fakeColumns, $identifiableAttribute, $Type
Loading history...
22
    use HasRoles;
0 ignored issues
show
introduced by
The trait Spatie\Permission\Traits\HasRoles requires some properties which are not provided by App\Models\User: $name, $map, $permissions, $roles, $guard_name
Loading history...
23
    use LogsActivity;
24
25
    protected $guarded = ['id'];
26
27
    protected static bool $logFillable = true;
28
29
    protected $hidden = ['password', 'remember_token'];
30
31
    protected $dispatchesEvents = [
32
        'deleting' => UserDeleting::class,
33
    ];
34
35
    public function getEmailForPasswordReset() : string
36
    {
37
        return $this->email;
38
    }
39
40
    public function isTeacher()
41
    {
42
        return Teacher::whereId($this->id)->count() > 0;
43
    }
44
45
    public function isStudent()
46
    {
47
        return Student::whereId($this->id)->count() > 0;
48
    }
49
50
    public function student()
51
    {
52
        return $this->hasOne(Student::class, 'id', 'id');
53
    }
54
55
    public function teacher()
56
    {
57
        return $this->hasOne(Teacher::class, 'id', 'id');
58
    }
59
60
    public function getFirstnameAttribute($value)
61
    {
62
        return Str::title($value);
0 ignored issues
show
Bug introduced by
The method title() does not exist on Illuminate\Support\Str. ( Ignorable by Annotation )

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

62
        return Str::/** @scrutinizer ignore-call */ title($value);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
63
    }
64
65
    public function getLastnameAttribute($value)
66
    {
67
        return Str::upper($value);
0 ignored issues
show
Bug introduced by
The method upper() does not exist on Illuminate\Support\Str. ( Ignorable by Annotation )

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

67
        return Str::/** @scrutinizer ignore-call */ upper($value);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
68
    }
69
70
    public function getNameAttribute()
71
    {
72
        return $this->firstname.' '.$this->lastname;
73
    }
74
75
    public function getIdnumberAttribute()
76
    {
77
        if ($this->isStudent()) {
78
            return $this->student->idnumber;
79
        }
80
    }
81
82
    public function getAddressAttribute()
83
    {
84
        if ($this->isStudent()) {
85
            return $this->student->address;
86
        }
87
    }
88
89
    public function getBirthdateAttribute()
90
    {
91
        if ($this->isStudent()) {
92
            return $this->student->birthdate;
93
        }
94
    }
95
96
    public function getTeacherIdAttribute()
97
    {
98
        return $this->teacher->id ?? null;
99
    }
100
101
    public function getStudentIdAttribute()
102
    {
103
        return $this->student->id ?? null;
104
    }
105
106
    public function getForceUpdateAttribute()
107
    {
108
        return $this->force_update ?? null;
109
    }
110
111
    public function setEmailAttribute($value)
112
    {
113
        $this->attributes['email'] = strtolower($value);
114
    }
115
}
116