Passed
Push — develop ( 2fff64...5f0aa7 )
by Septianata
04:06
created

Attribute::getIsActiveBadgeAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 11
ccs 0
cts 8
cp 0
rs 10
cc 2
nc 2
nop 0
crap 6
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
 *
19
 * @see \App\Models\User
20
 */
21
trait Attribute
22
{
23
    /**
24
     * Set "password" attribute value.
25
     *
26
     * @param  mixed  $value
27
     * @return void
28
     */
29 18
    public function setPasswordAttribute($value)
30
    {
31 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...
32
33 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...
34
    }
35
36
    /**
37
     * Return "is_active_badge" attribute value.
38
     *
39
     * @return string
40
     */
41
    public function getIsActiveBadgeAttribute(): string
42
    {
43
        if ($this->is_active) {
44
            return sprintf(<<<'html'
45
            <div class="badge badge-success">%s</div>
46
            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

46
            html, /** @scrutinizer ignore-type */ trans('Active'));
Loading history...
47
        }
48
49
        return sprintf(<<<'html'
50
        <div class="badge badge-danger">%s</div>
51
        html, trans('Not Active'));
52
    }
53
}
54