Passed
Push — develop ( b27e40...fcd18c )
by Septianata
43:54
created

Attribute::getRoleAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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 $fullname
10
 * @property string $email
11
 * @property string $phone_country
12
 * @property \Propaganistas\LaravelPhone\PhoneNumber $phone
13
 * @property \Illuminate\Support\Carbon $email_verified_at
14
 * @property string $password
15
 * @property string $remember_token
16
 * @property boolean $is_active
17
 * @property string $is_active_badge
18
 * @property-read string $role
19
 *
20
 * @see \App\Models\User
21
 */
22
trait Attribute
23
{
24
    /**
25
     * Set "password" attribute value.
26
     *
27
     * @param  mixed  $value
28
     * @return void
29 51
     */
30
    public function setPasswordAttribute($value)
31 51
    {
32
        $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...
33 51
34
        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...
35
    }
36
37
    /**
38
     * Return "is_active_badge" attribute value.
39
     *
40
     * @return string
41
     */
42
    public function getIsActiveBadgeAttribute(): string
43
    {
44
        if ($this->is_active) {
45
            return sprintf(<<<'html'
46
            <div class="badge badge-success">%s</div>
47
            html, trans('Active'));
0 ignored issues
show
Bug introduced by
It seems like trans('Active') can also be of type array and array; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

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

47
            html, /** @scrutinizer ignore-type */ trans('Active'));
Loading history...
48
        }
49
50
        return sprintf(<<<'html'
51
        <div class="badge badge-danger">%s</div>
52
        html, trans('Not Active'));
53
    }
54
55
    /**
56
     * Return "role" attribute value.
57
     *
58
     * @return string
59
     */
60
    public function getRoleAttribute(): string
61
    {
62
        $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

62
        $this->/** @scrutinizer ignore-call */ 
63
               load('roles:id,name');
Loading history...
63
64
        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...
65
    }
66
}
67