User   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 16
c 0
b 0
f 0
dl 0
loc 54
ccs 6
cts 6
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setPasswordAttribute() 0 4 3
A servers() 0 3 1
1
<?php
2
3
namespace Gameap\Models;
4
5
use Illuminate\Foundation\Auth\User as Authenticatable;
6
use Illuminate\Notifications\Notifiable;
7
use Silber\Bouncer\Database\HasRolesAndAbilities;
8
use Laravel\Sanctum\HasApiTokens;
9
10
/**
11
 * @property string $login
12
 * @property string $email
13
 * @property string $name
14
 * @property iterable $tokens
15
 *
16
 * @property Server[] $servers
17
 */
18
class User extends Authenticatable
19
{
20
    use HasApiTokens;
21
    use Notifiable;
22
    use HasRolesAndAbilities;
23
24
    /**
25
     * The attributes that are mass assignable.
26
     *
27
     * @var array
28
     */
29
    protected $fillable = [
30
        'login', 'email', 'password', 'name',
31
    ];
32
33
    /**
34
     * The attributes that should be hidden for arrays.
35
     *
36
     * @var array
37
     */
38
    protected $hidden = [
39
        'password', 'remember_token',
40
    ];
41
42
    /**
43
     * Validation rules
44
     *
45
     * @var array
46
     */
47
    protected static $rules = [
48
        'login'    => 'sometimes|string|max:255|unique:users',
49
        'email'    => 'sometimes|string|email|max:255|unique:users',
50
        'password' => 'nullable|sometimes|string|min:6',
51
        'name'     => 'string|nullable|max:255',
52 36
    ];
53
54 36
    /**
55 36
     * Hash password
56
     *
57 36
     * @param $value
58
     */
59
    public function setPasswordAttribute($value): void
60
    {
61
        if ($value != null && strlen($value) > 0) {
62 12
            $this->attributes['password'] = bcrypt($value);
63
        }
64 12
    }
65
66
    /**
67
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
68
     */
69
    public function servers()
70
    {
71
        return $this->belongsToMany(Server::class);
72
    }
73
}
74