User   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Test Coverage

Coverage 95%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
eloc 25
c 1
b 0
f 0
dl 0
loc 78
ccs 19
cts 20
cp 0.95
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A sendPasswordResetNotification() 0 3 1
A hasAccess() 0 9 2
A getFirstRedirect() 0 23 6
A role() 0 3 1
A boot() 0 4 1
1
<?php namespace Distilleries\Expendable\Models;
2
3
use Distilleries\Expendable\Contracts\LockableContract;
4
use Distilleries\Expendable\Helpers\UserUtils;
5
use Distilleries\Expendable\Mails\ResetPasswordNotification;
6
use Distilleries\PermissionUtil\Contracts\PermissionUtilContract;
7
use Illuminate\Auth\Authenticatable;
8
use Illuminate\Auth\Passwords\CanResetPassword;
9
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
10
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
11
use Illuminate\Foundation\Auth\Access\Authorizable;
12
use Illuminate\Notifications\Notifiable;
13
14
class User extends BaseModel implements AuthenticatableContract, CanResetPasswordContract, PermissionUtilContract, LockableContract {
15
16
    use Authenticatable, Authorizable, CanResetPassword, \Distilleries\Expendable\Models\StatusTrait, LockableTrait;
0 ignored issues
show
Bug introduced by
The trait Illuminate\Auth\Passwords\CanResetPassword requires the property $email which is not provided by Distilleries\Expendable\Models\User.
Loading history...
Bug introduced by
The trait Illuminate\Auth\Authenticatable requires the property $password which is not provided by Distilleries\Expendable\Models\User.
Loading history...
17
    use Notifiable;
0 ignored issues
show
introduced by
The trait Illuminate\Notifications\Notifiable requires some properties which are not provided by Distilleries\Expendable\Models\User: $email, $phone_number
Loading history...
18
    protected $tabPermission = [];
19
    protected $fillable = [
20
        'email',
21
        'password',
22
        'status',
23
        'role_id'
24
    ];
25
26
    /**
27
     * The attributes excluded from the model's JSON form.
28
     *
29
     * @var array
30
     */
31
    protected $hidden = ['password', 'remember_token'];
32
33 146
    public function role()
34
    {
35 146
        return $this->belongsTo('Distilleries\Expendable\Models\Role');
36
    }
37
38 188
    public static function boot()
39
    {
40 188
        parent::boot();
41 188
        self::observe(new \Distilleries\Expendable\Observers\PasswordObserver);
42
    }
43
44
45
46 128
    public function hasAccess($key)
47
    {
48
49 128
        if (!empty($this->role->overide_permission))
50
        {
51 126
            return true;
52
        }
53
54 2
        return UserUtils::hasAccess($key);
55
    }
56
57 10
    public function getFirstRedirect($left)
58
    {
59 10
        foreach ($left as $item)
60
        {
61
62 10
            if (!empty($item['action']) && $this->hasAccess($item['action']))
63
            {
64 8
                return preg_replace('/\/index/i', '', action($item['action']));
65
66 2
            } else if (!empty($item['submenu']))
67
            {
68 2
                $redirect = $this->getFirstRedirect($item['submenu']);
69
70 2
                if (!empty($redirect))
71
                {
72
                    return $redirect;
73
                }
74
75
            }
76
77
        }
78
79 2
        return '';
80
    }
81
82
83
    /**
84
     * Send the password reset notification.
85
     *
86
     * @param  string  $token
87
     * @return void
88
     */
89 2
    public function sendPasswordResetNotification($token)
90
    {
91 2
        $this->notify(new ResetPasswordNotification($token));
92
    }
93
94
}
95