User::getHomeUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Services\Auth\Back;
4
5
use Mail;
6
use App\Services\Auth\User as BaseUser;
7
use App\Services\Auth\Back\Enums\UserRole;
8
use App\Services\Auth\Back\Enums\UserStatus;
9
use App\Services\Auth\Back\Mail\ResetPassword;
10
use App\Services\Auth\Back\Exceptions\UserIsAlreadyActivated;
11
12
/**
13
 * @property \App\Services\Auth\Back\Enums\UserRole $role
14
 * @property \App\Services\Auth\Back\Enums\UserStatus $status
15
 */
16
class User extends BaseUser
17
{
18
    protected $table = 'users_back';
19
20
    public function guardDriver(): string
21
    {
22
        return 'back';
23
    }
24
25
    public function getHomeUrl(): string
26
    {
27
        return url('blender');
28
    }
29
30
    public function getProfileUrl(): string
31
    {
32
        return action('Back\AdministratorsController@edit', $this->id);
0 ignored issues
show
Documentation introduced by
$this->id is of type integer, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
33
    }
34
35
    public function getStatusAttribute(): string
36
    {
37
        return new UserStatus($this->attributes['status']);
0 ignored issues
show
Unused Code introduced by
The call to UserStatus::__construct() has too many arguments starting with $this->attributes['status'].

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
38
    }
39
40
    public function setStatusAttribute(string $status)
41
    {
42
        $this->attributes['status'] = $status;
43
    }
44
45
    public function hasStatus(string $status): bool
46
    {
47
        return $this->status === $status;
48
    }
49
50
    public function isActive(): bool
51
    {
52
        return $this->hasStatus(UserStatus::ACTIVE);
53
    }
54
55
    public function activate(): User
56
    {
57
        if ($this->status !== UserStatus::WAITING_FOR_APPROVAL) {
58
            throw new UserIsAlreadyActivated();
59
        }
60
61
        $this->status = UserStatus::ACTIVE;
62
63
        return $this;
64
    }
65
66
    public function getRoleAttribute(): string
67
    {
68
        return $this->attributes['role'];
69
    }
70
71
    public function setRoleAttribute(string $role)
72
    {
73
        $this->attributes['role'] = $role;
74
    }
75
76
    public function hasRole(UserRole $role): bool
77
    {
78
        return $this->role === $role;
79
    }
80
81
    /**
82
     * Send the password reset notification.
83
     *
84
     * @param string $token
85
     */
86
    public function sendPasswordResetNotification($token)
87
    {
88
        Mail::to($this->email)->send(new ResetPassword($this, $token));
89
    }
90
91
    public function delete()
92
    {
93
        if (current_back_user() && current_back_user()->id === $this->id) {
94
            abort(406);
95
        }
96
97
        return parent::delete();
98
    }
99
}
100