Passed
Push — develop ( 95decf...daf980 )
by Septianata
06:53 queued 33s
created

Attribute::getIsActiveBadgeAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.2109

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 11
ccs 5
cts 8
cp 0.625
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.2109
1
<?php
2
3
namespace App\Models\Concerns\User;
4
5
use Illuminate\Support\Facades\Hash;
6
7
/**
8
 * @property string|null $telegram_chat_id
9
 * @property string $username
10
 * @property string $fullname
11
 * @property string $email
12
 * @property string $phone_country
13
 * @property \Propaganistas\LaravelPhone\PhoneNumber $phone
14
 * @property \Illuminate\Support\Carbon $email_verified_at
15
 * @property string $password
16
 * @property string $remember_token
17
 * @property boolean $is_active
18
 * @property string $is_active_badge
19
 * @property-read string $role
20
 *
21
 * @see \App\Models\User
22
 */
23
trait Attribute
24
{
25
    /**
26
     * Set "password" attribute value.
27
     *
28
     * @param  mixed  $value
29
     * @return void
30
     */
31 74
    public function setPasswordAttribute($value)
32
    {
33 74
        $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...
34
35 74
        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...
36
    }
37
38
    /**
39
     * Return "is_active_badge" attribute value.
40
     *
41
     * @return string
42
     */
43 1
    public function getIsActiveBadgeAttribute(): string
44
    {
45 1
        if ($this->is_active) {
46 1
            return sprintf(<<<'html'
47 1
            <div class="badge badge-success">%s</div>
48 1
            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

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

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