User::profile()   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
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace App;
4
5
//use Illuminate\Foundation\Auth\User as Authenticatable;
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
6
use App\Libraries\Presenterable\Presenterable;
7
use App\Libraries\Presenterable\Presenters\UserPresenter;
8
use App\Repositories\RolesRepository;
9
use App\Traits\ActivateableTrait;
10
use App\Traits\Confirmed;
11
use Keyhunter\Administrator\AuthRepository as Authenticatable;
12
use App\Traits\HasImages;
13
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
14
use Illuminate\Auth\Passwords\CanResetPassword;
15
16
class User extends Authenticatable implements CanResetPasswordContract
17
{
18
    use Presenterable, Confirmed, ActivateableTrait, HasImages, CanResetPassword;
19
20
    /**
21
     * The attributes that are mass assignable.
22
     *
23
     * @var array
24
     */
25
    protected $fillable = [
26
        'name', 'email', 'password', 'role_id', 'confirmation_code', 'confirmed'
27
    ];
28
29
    /**
30
     * The attributes that should be hidden for arrays.
31
     *
32
     * @var array
33
     */
34
    protected $hidden = [
35
        'password', 'remember_token',
36
    ];
37
38
    /**
39
     * @var UserPresenter
40
     */
41
    protected $presenter = UserPresenter::class;
42
43
    /**
44
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
45
     */
46
    public function vendors()
47
    {
48
        return $this->hasMany(Vendor::class);
49
    }
50
51
    /**
52
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
53
     */
54
    public function wallet()
55
    {
56
        return $this->hasOne(Wallet::class);
57
    }
58
59
    /**
60
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
61
     */
62
    public function profile()
63
    {
64
        return $this->hasOne(Profile::class, 'user_id', 'id');
65
    }
66
67
    /**
68
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
69
     */
70
    public function involved()
71
    {
72
        return $this->hasMany(Involved::class, 'user_id', 'id');
73
    }
74
75
76
    /**
77
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
78
     */
79
    public function socialite()
80
    {
81
        return $this->belongsTo(Socialite::class, 'id', 'user_id');
82
    }
83
84
    /**
85
     * Check if current user is socialite user.
86
     *
87
     * @return bool
88
     */
89
    public function isSocialite()
90
    {
91
        return (bool)$this->socialite;
0 ignored issues
show
Documentation introduced by
The property socialite does not exist on object<App\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
92
    }
93
94
    /**
95
     * Check if user have avatar.
96
     *
97
     * @return bool
98
     */
99
    public function checkAvatar()
100
    {
101
        return (bool)$this->images()->avatar()->first();
102
    }
103
104
    public function isAdmin()
105
    {
106
        $admin = (new RolesRepository)->getAdminRole();
107
108
        return $this->role_id == $admin->id;
0 ignored issues
show
Documentation introduced by
The property role_id does not exist on object<App\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
109
    }
110
111
    /**
112
     * Check if user has wallet.
113
     *
114
     * @return bool
115
     */
116
    public function haveWallet()
117
    {
118
        //return (bool) $this->wallet()->first();
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
119
    }
120
}
121