User::avatar()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App;
4
5
use Illuminate\Auth\Authenticatable;
6
use Illuminate\Auth\Passwords\CanResetPassword;
7
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
8
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
9
use Illuminate\Database\Eloquent\Model;
10
11
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
12
{
13
    use Authenticatable,
14
        CanResetPassword;
15
16
    /**
17
     * The database table used by the model.
18
     *
19
     * @var string
20
     */
21
    protected $table = 'users';
22
23
    /**
24
     * The attributes that are mass assignable.
25
     *
26
     * @var array
27
     */
28
    protected $fillable = ['user_name', 'email', 'password', 'active', 'first_name', 'last_name', 'ban', 'ext', 'mobile', 'profile_pic',
29
        'phone_number', 'company', 'agent_sign', 'account_type', 'account_status',
30
        'assign_group', 'primary_dpt', 'agent_tzone', 'daylight_save', 'limit_access',
31
        'directory_listing', 'vacation_mode', 'role', 'internal_note', 'country_code', 'not_accept_ticket', 'is_delete', ];
32
33
    /**
34
     * The attributes excluded from the model's JSON form.
35
     *
36
     * @var array
37
     */
38
    protected $hidden = ['password', 'remember_token'];
39
40
    public function getProfilePicAttribute($value)
41
    {
42
        $info = $this->avatar();
43
        $pic = null;
44
        if ($info) {
45
            $pic = $this->checkArray('avatar', $info);
46
        }
47
        if (!$pic) {
48
            $pic = asset('uploads/profilepic/'.$value);
49
        }
50
        if (!$value) {
51
            $pic = \Gravatar::src($this->attributes['email']);
52
        }
53
54
        return $pic;
55
    }
56
57
    public function avatar()
58
    {
59
        $related = 'App\UserAdditionalInfo';
60
        $foreignKey = 'owner';
61
62
        return $this->hasMany($related, $foreignKey)->select('value')->where('key', 'avatar')->first();
63
    }
64
65
    public function getOrganizationRelation()
66
    {
67
        $related = "App\Model\helpdesk\Agent_panel\User_org";
68
        $user_relation = $this->hasMany($related, 'user_id');
69
        $relation = $user_relation->first();
70
        if ($relation) {
71
            $org_id = $relation->org_id;
72
            $orgs = new \App\Model\helpdesk\Agent_panel\Organization();
73
            $org = $orgs->where('id', $org_id);
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Model\helpdes...ent_panel\Organization>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
74
75
            return $org;
76
        }
77
    }
78
79 View Code Duplication
    public function getOrganization()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
    {
81
        $name = '';
82
        if ($this->getOrganizationRelation()) {
83
            $org = $this->getOrganizationRelation()->first();
84
            if ($org) {
85
                $name = $org->name;
86
            }
87
        }
88
89
        return $name;
90
    }
91
92 View Code Duplication
    public function getOrgWithLink()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
93
    {
94
        $name = '';
95
        $org = $this->getOrganization();
96
        if ($org !== '') {
97
            $orgs = $this->getOrganizationRelation()->first();
98
            if ($orgs) {
99
                $id = $orgs->id;
100
                $name = '<a href='.url('organizations/'.$id).'>'.ucfirst($org).'</a>';
101
            }
102
        }
103
104
        return $name;
105
    }
106
107
    public function getEmailAttribute($value)
108
    {
109
        if (!$value) {
110
            $value = \Lang::get('lang.not-available');
111
        }
112
113
        return $value;
114
    }
115
116
    public function getExtraInfo($id = '')
117
    {
118
        if ($id === '') {
119
            $id = $this->attributes['id'];
120
        }
121
        $info = new UserAdditionalInfo();
122
        $infos = $info->where('owner', $id)->lists('value', 'key')->toArray();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\UserAdditionalInfo>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
123
124
        return $infos;
125
    }
126
127 View Code Duplication
    public function checkArray($key, $array)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
128
    {
129
        $value = '';
130
        if (is_array($array)) {
131
            if (array_key_exists($key, $array)) {
132
                $value = $array[$key];
133
            }
134
        }
135
136
        return $value;
137
    }
138
139
    public function twitterLink()
140
    {
141
        $html = '';
142
        $info = $this->getExtraInfo();
143
        $username = $this->checkArray('username', $info);
144
        if ($username !== '') {
145
            $html = "<a href='https://twitter.com/".$username."' target='_blank'><i class='fa fa-twitter'> </i> Twitter</a>";
146
        }
147
148
        return $html;
149
    }
150
151
    public function name()
152
    {
153
        $first_name = $this->first_name;
0 ignored issues
show
Documentation introduced by
The property first_name does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
154
        $last_name = $this->last_name;
0 ignored issues
show
Documentation introduced by
The property last_name does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
155
        $name = $this->user_name;
0 ignored issues
show
Documentation introduced by
The property user_name does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
156
        if ($first_name !== '' && $first_name !== null) {
157
            if ($last_name !== '' && $last_name !== null) {
158
                $name = $first_name.' '.$last_name;
159
            } else {
160
                $name = $first_name;
161
            }
162
        }
163
164
        return $name;
165
    }
166
167
    public function getFullNameAttribute()
168
    {
169
        return $this->name();
170
    }
171
172
//    public function save() {
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
173
//        dd($this->id);
174
//        parent::save();
175
//    }
176
177
//    public function save(array $options = array()) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
178
//        parent::save($options);
179
//        dd($this->where('id',$this->id)->select('first_name','last_name','user_name','email')->get()->toJson());
180
//    }
181
}
182