Completed
Push — master ( 02f92d...9c9507 )
by Sebastian
15:38
created

User::setStatusAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace App\Services\Auth\Back;
4
5
use App\Services\Auth\Back\Enums\UserRole;
6
use App\Services\Auth\Back\Enums\UserStatus;
7
use App\Services\Auth\User as BaseUser;
8
9
/**
10
 * @property \App\Services\Auth\Back\Enums\UserRole $role
11
 * @property \App\Services\Auth\Back\Enums\UserStatus $status
12
 */
13
class User extends BaseUser
14
{
15
    protected $table = 'users_back';
16
    protected $presenter = UserPresenter::class;
17
18
    public function guardDriver() : string
19
    {
20
        return 'back';
21
    }
22
23
    public function getHomeUrl() : string
24
    {
25
        return url('blender');
26
    }
27
28
    public function getProfileUrl() : string
29
    {
30
        return action('Back\BackUserController@edit', ['id' => $this->id]);
31
    }
32
33
    public function getStatusAttribute() : UserStatus
34
    {
35
        return new UserStatus($this->attributes['status']);
36
    }
37
38
    public function setStatusAttribute(UserStatus $status)
39
    {
40
        $this->attributes['status'] = $status->getValue();
41
    }
42
43
    public function hasStatus(UserStatus $status) : bool
44
    {
45
        return $this->status->equals($status);
46
    }
47
48
    public function isActive() : bool
49
    {
50
        return $this->hasStatus(UserStatus::ACTIVE());
51
    }
52
53
    public function activate() : User
54
    {
55
        if ($this->status->doesntEqual(UserStatus::WAITING_FOR_APPROVAL())) {
56
            throw new UserIsAlreadyActivated();
57
        }
58
59
        $this->status = UserStatus::ACTIVE();
60
61
        return $this;
62
    }
63
64
    public function getRoleAttribute() : UserRole
65
    {
66
        return new UserRole($this->attributes['role']);
67
    }
68
69
    public function setRoleAttribute(UserRole $role)
70
    {
71
        $this->attributes['role'] = $role->getValue();
72
    }
73
74
    public function hasRole(UserRole $role) : bool
75
    {
76
        return $this->role->equals($role);
77
    }
78
}
79