Completed
Push — master ( 7c1cbc...aa55a0 )
by Abdelrahman
08:51
created

User::hasAbilityTo()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * NOTICE OF LICENSE
5
 *
6
 * Part of the Rinvex Fort Package.
7
 *
8
 * This source file is subject to The MIT License (MIT)
9
 * that is bundled with this package in the LICENSE file.
10
 *
11
 * Package: Rinvex Fort Package
12
 * License: The MIT License (MIT)
13
 * Link:    https://rinvex.com
14
 */
15
16
namespace Rinvex\Fort\Models;
17
18
use Rinvex\Fort\Traits\HasRoles;
19
use Rinvex\Fort\Traits\CanVerifyEmail;
20
use Rinvex\Fort\Traits\Authenticatable;
21
use Illuminate\Database\Eloquent\Model;
22
use Illuminate\Notifications\Notifiable;
23
use Rinvex\Fort\Traits\CanResetPassword;
24
use Illuminate\Database\Eloquent\SoftDeletes;
25
use Rinvex\Fort\Contracts\CanVerifyEmailContract;
26
use Rinvex\Fort\Contracts\AuthenticatableContract;
27
use Illuminate\Foundation\Auth\Access\Authorizable;
28
use Rinvex\Fort\Contracts\CanResetPasswordContract;
29
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
30
31
class User extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract, CanVerifyEmailContract
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 131 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
32
{
33
    use Notifiable, Authenticatable, Authorizable, CanResetPassword, CanVerifyEmail, SoftDeletes, HasRoles;
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    protected $dates = [
39
        'email_verified_at',
40
        'deleted_at',
41
        'birthdate',
42
        'login_at',
43
        'active_at',
44
    ];
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    protected $fillable = [
50
        'username',
51
        'password',
52
        'two_factor',
53
        'email',
54
        'email_verified',
55
        'email_verified_at',
56
        'phone',
57
        'phone_verified',
58
        'phone_verified_at',
59
        'prefix',
60
        'first_name',
61
        'middle_name',
62
        'last_name',
63
        'sufix',
64
        'job_title',
65
        'country',
66
        'birthdate',
67
        'gender',
68
        'moderated',
69
        'login_at',
70
        'active_at',
71
    ];
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    protected $hidden = [
77
        'password',
78
        'two_factor',
79
        'remember_token',
80
    ];
81
82
    /**
83
     * Create a new Eloquent model instance.
84
     *
85
     * @param array $attributes
86
     *
87
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
88
     */
89
    public function __construct(array $attributes = [])
90
    {
91
        parent::__construct($attributes);
92
93
        $this->setTable(config('rinvex.fort.tables.users'));
94
    }
95
96
    /**
97
     * A user may have multiple direct abilities.
98
     *
99
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
100
     */
101
    public function abilities()
102
    {
103
        return $this->belongsToMany(config('rinvex.fort.models.ability'), config('rinvex.fort.tables.ability_user'))
104
                    ->withTimestamps();
105
    }
106
107
    /**
108
     * A user may have multiple roles.
109
     *
110
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
111
     */
112
    public function roles()
113
    {
114
        return $this->belongsToMany(config('rinvex.fort.models.role'), config('rinvex.fort.tables.role_user'))
115
                    ->withTimestamps();
116
    }
117
118
    /**
119
     * A user may have multiple persistences.
120
     *
121
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
122
     */
123
    public function persistences()
124
    {
125
        return $this->hasMany(config('rinvex.fort.models.persistence'));
126
    }
127
128
    /**
129
     * A user may have multiple socialites.
130
     *
131
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
132
     */
133
    public function socialites()
134
    {
135
        return $this->hasMany(config('rinvex.fort.models.socialite'));
136
    }
137
138
    /**
139
     * Determine if the user may perform the given ability.
140
     *
141
     * @param string|array|\Rinvex\Fort\Models\Ability|\Illuminate\Support\Collection $role
0 ignored issues
show
Bug introduced by
There is no parameter named $role. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
142
     *
143
     * @return bool
144
     */
145
    public function hasAbilityTo($ability)
146
    {
147
        return $this->hasDirectAbility($ability) || $this->hasAbilityViaRole($ability);
148
    }
149
}
150