Passed
Push — develop ( 4cbaa0...09ba9e )
by Ngoding
05:32
created

Attribute::getRoleAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
namespace App\Models\Concerns\User;
4
5
use Illuminate\Support\Facades\Hash;
6
7
/**
8
 * @property string $username
9
 * @property string $name
10
 * @property string $email
11
 * @property \Illuminate\Support\Carbon $email_verified_at
12
 * @property string $password
13
 * @property-read string $remember_token
14
 * @property-read string $role
15
 * @property-read string $profile_image
16
 *
17
 * @see \App\Models\User
18
 */
19
trait Attribute
20
{
21
    /**
22
     * Set "password" attribute value.
23
     *
24
     * @param  mixed  $value
25
     * @return void
26
     */
27 18
    public function setPasswordAttribute($value)
28
    {
29 18
        $this->attributes['password'] = Hash::make($value);
0 ignored issues
show
Bug Best Practice introduced by
The property attributes does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
30
31 18
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type App\Models\Concerns\User\Attribute which is incompatible with the documented return type void.
Loading history...
32
    }
33
34
    /**
35
     * Return "role" attribute value.
36
     *
37
     * @return string
38
     */
39 1
    public function getRoleAttribute(): string
40
    {
41 1
        $this->load('roles:id,name');
0 ignored issues
show
Bug introduced by
It seems like load() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
        $this->/** @scrutinizer ignore-call */ 
42
               load('roles:id,name');
Loading history...
42
43 1
        return $this->roles->first()->name;
0 ignored issues
show
Bug introduced by
The property roles does not exist on App\Models\Concerns\User\Attribute. Did you mean role?
Loading history...
44
    }
45
46
    /**
47
     * Return "profile_image" attribute value.
48
     *
49
     * @return string
50
     */
51 1
    public function getProfileImageAttribute(): string
52
    {
53 1
        return gravatar_image($this->email);
54
    }
55
}
56