User   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 46
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A role() 0 4 1
A hasRole() 0 4 1
1
<?php namespace WITR;
2
3
use Illuminate\Auth\Authenticatable;
4
use Illuminate\Database\Eloquent\Model;
5
use Illuminate\Auth\Passwords\CanResetPassword;
6
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
7
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
8
9
class User extends Model implements AuthenticatableContract, CanResetPasswordContract {
10
11
	use Authenticatable, CanResetPassword;
12
13
	/**
14
	 * The database table used by the model.
15
	 *
16
	 * @var string
17
	 */
18
	protected $table = 'user';
19
20
	/**
21
	 * The attributes that are mass assignable.
22
	 *
23
	 * @var array
24
	 */
25
	protected $fillable = ['name', 'email', 'password', 'picture', 'user_role'];
26
27
	/**
28
	 * The attributes excluded from the model's JSON form.
29
	 *
30
	 * @var array
31
	 */
32
	protected $hidden = ['password', 'remember_token'];
33
34
    public $timestamps = false;
35
36
	/**
37
     * @return mixed
38
     */
39
    public function role()
40
    {
41
        return $this->belongsTo('WITR\Role',  'user_role', 'id');
42
    }
43
44
    /**
45
     * Does the user have a particular role?
46
     *
47
     * @param $name
48
     * @return bool
49
     */
50
    public function hasRole($name)
51
    {
52
        return $this->role->name == $name;
0 ignored issues
show
Documentation introduced by
The property role does not exist on object<WITR\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...
53
    }
54
}
55