Admin::getGreetings()   B
last analyzed

Complexity

Conditions 11
Paths 6

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 16
rs 7.3166
c 0
b 0
f 0
cc 11
nc 6
nop 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace App;
4
5
use Carbon\Carbon;
6
use Illuminate\Notifications\Notifiable;
7
use Illuminate\Contracts\Auth\MustVerifyEmail;
8
use Illuminate\Foundation\Auth\User as Authenticatable;
9
10
class Admin extends Authenticatable
11
{
12
    use Notifiable;
0 ignored issues
show
introduced by
The trait Illuminate\Notifications\Notifiable requires some properties which are not provided by App\Admin: $email, $phone_number
Loading history...
13
14
    protected $guard = 'admin';
15
16
17
    /**
18
     * The attributes that are mass assignable.
19
     *
20
     * @var array
21
     */
22
    protected $fillable = [
23
        'name', 'profile_picture', 'email', 'password',
24
    ];
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
    /**
38
     * The attributes that should be cast to native types.
39
     *
40
     * @var array
41
     */
42
    protected $casts = [
43
        'email_verified_at' => 'datetime',
44
    ];
45
46
47
    /**
48
     * @var array
49
     */
50
    protected $dates = [
51
        'created_at',
52
        'updated_at'
53
    ];
54
55
56
    /**
57
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
58
     */
59
    public function article()
60
    {
61
        return $this->hasMany('App\Articles');
62
    }
63
64
65
    /**
66
     * @return string
67
     */
68
    public function getGreetings()
69
    {
70
        $h = Carbon::now()->format('H');
71
72
        if ($h >= 0 && $h < 6) {
73
            return "<i class='fa far fa-surprise fa-2x'></i>&nbsp;&nbsp;Wow, ini masih pagi loh ";
74
        } elseif ($h >= 6 && $h < 11) {
75
            return "<i class='fa far fa-laugh-beam fa-2x'></i>&nbsp;&nbsp;Selamat pagi ";
76
        } elseif ($h >= 11 && $h <= 14) {
77
            return "<i class='fa far fa-smile-wink fa-2x'></i>&nbsp;&nbsp;Selamat siang ";
78
        } elseif ($h > 14 && $h <= 16) {
79
            return "<i class='fa far fa-smile-beam fa-2x'></i>&nbsp;&nbsp;Selamat sore ";
80
        } elseif ($h >= 17 && $h < 20) {
81
            return "<i class='fa far fa-grin-stars fa-2x'></i>&nbsp;&nbsp;Senja yang indah ya ";
82
        } else {
83
            return "<i class='fa far fa-bed fa-2x'></i>&nbsp;&nbsp;Sudah malam, sebaiknya kamu istirahat ";
84
        }
85
    }
86
}
87