Passed
Push — master ( d58bf8...6af014 )
by Faiq
04:49
created

Doctor   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 37
dl 0
loc 127
rs 10
c 0
b 0
f 0
wmc 20

9 Methods

Rating   Name   Duplication   Size   Complexity  
A specialty() 0 3 1
A article() 0 3 1
A thread() 0 2 1
A city() 0 2 1
A getLocation() 0 5 1
B getGreetings() 0 16 11
A trimStr() 0 6 2
A hospital() 0 2 1
A getSpecialty() 0 5 1
1
<?php
2
3
namespace App;
4
5
use Carbon\Carbon;
6
use App\City;
7
use App\DoctorSpecialization;
8
use Illuminate\Notifications\Notifiable;
9
use Illuminate\Contracts\Auth\MustVerifyEmail;
10
use Illuminate\Foundation\Auth\User as Authenticatable;
11
12
class Doctor extends Authenticatable
13
{
14
    use Notifiable;
0 ignored issues
show
introduced by
The trait Illuminate\Notifications\Notifiable requires some properties which are not provided by App\Doctor: $email, $phone_number
Loading history...
15
16
    protected $guard = 'doctor';
17
18
    /**
19
     * The attributes that are mass assignable.
20
     *
21
     * @var array
22
     */
23
    protected $fillable = [
24
        'name', 'biography', 'profile_picture', 'email', 'password'
25
    ];
26
27
    /**
28
     * The attributes that should be hidden for arrays.
29
     *
30
     * @var array
31
     */
32
    protected $hidden = [
33
        'password', 'remember_token',
34
    ];
35
36
    /**
37
     * The attributes that should be cast to native types.
38
     *
39
     * @var array
40
     */
41
    protected $casts = [
42
        'email_verified_at' => 'datetime',
43
    ];
44
45
    /**
46
     * @var array
47
     */
48
    protected $dates = [
49
        'created_at',
50
        'updated_at'
51
    ];
52
53
    /**
54
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
55
     */
56
    public function article()
57
    {
58
        return $this->hasMany('App\Articles');
59
    }
60
61
//    /**
62
//     * @return \Illuminate\Database\Eloquent\Relations\HasMany
63
//     */
64
//    public function detail()
65
//    {
66
//        return $this->hasMany('App\DoctorDetail');
67
//    }
68
69
70
    public function specialty()
71
    {
72
        return $this->belongsTo('App\DoctorSpecialization', 'specialization_id');
73
    }
74
75
    public function city() {
76
        return $this->belongsTo('App\City', 'city_id');
77
    }
78
79
    public function thread() {
80
        return $this->hasMany('App\Thread', 'doctor_id');
81
    }
82
83
    public function hospital() {
84
        return $this->belongsToMany('App\Hospital', 'doctor_details', 'doctor_id', 'hospital_id');
85
    }
86
87
    /**
88
     * @param $str
89
     * @return string
90
     */
91
    public function trimStr($str)
92
    {
93
        if(strlen($str) > 20) {
94
            return substr($str, 0, 20)."...";
95
        }
96
        return $str;
97
    }
98
99
    /**
100
     * @return string
101
     */
102
    public function getGreetings()
103
    {
104
        $h = Carbon::now()->format('H');
105
106
        if ($h >= 0 && $h < 6) {
107
            return "<i class='fa far fa-surprise fa-2x'></i>&nbsp;&nbsp;Wow, ini masih pagi loh ";
108
        } elseif ($h >= 6 && $h < 11) {
109
            return "<i class='fa far fa-laugh-beam fa-2x'></i>&nbsp;&nbsp;Selamat pagi ";
110
        } elseif ($h >= 11 && $h <= 14) {
111
            return "<i class='fa far fa-smile-wink fa-2x'></i>&nbsp;&nbsp;Selamat siang ";
112
        } elseif ($h > 14 && $h <= 16) {
113
            return "<i class='fa far fa-smile-beam fa-2x'></i>&nbsp;&nbsp;Selamat sore ";
114
        } elseif ($h >= 17 && $h < 20) {
115
            return "<i class='fa far fa-grin-stars fa-2x'></i>&nbsp;&nbsp;Senja yang indah ya ";
116
        } else {
117
            return "<i class='fa far fa-bed fa-2x'></i>&nbsp;&nbsp;Sudah malam, sebaiknya kamu istirahat ";
118
        }
119
    }
120
121
    /**
122
     * @return mixed
123
     */
124
    public function getSpecialty()
125
    {
126
        $specialtyId = $this->getAttributeValue('specialization_id');
127
128
        return $specialty = DoctorSpecialization::find($specialtyId);
0 ignored issues
show
Unused Code introduced by
The assignment to $specialty is dead and can be removed.
Loading history...
129
    }
130
131
    /**
132
     * @return mixed
133
     */
134
    public function getLocation()
135
    {
136
        $locationId = $this->getAttributeValue('city_id');
137
138
        return $loc = City::find($locationId);
0 ignored issues
show
Unused Code introduced by
The assignment to $loc is dead and can be removed.
Loading history...
139
    }
140
}
141