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

Attribute   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 27.27%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
c 1
b 0
f 0
dl 0
loc 31
ccs 3
cts 11
cp 0.2727
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getIsActiveBadgeAttribute() 0 11 2
A setPasswordAttribute() 0 5 1
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