User   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 86
Duplicated Lines 9.3 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 8
loc 86
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A creator() 0 4 1
A group() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace App;
4
5
use Illuminate\Foundation\Auth\User as Authenticatable;
6
7
class User extends Authenticatable
8
{
9
    const USER_LEVEL_LOCAL  = 1;
10
    const USER_LEVEL_GLOBAL = 3;
11
    const USER_LEVEL_ADMIN  = 5;
12
    const USER_LEVEL_SUPER  = 9;
13
14
    const USER_DISABLED = 0;
15
    const USER_ENABLED = 1;
16
17
    const USER_STATUS = [
18
        0 => [  'text' => 'users.disabled',
19
                'icon' => '',
20
                'unicon' => '' ],
21
        1 => [  'text' => 'users.enabled',
22
                'icon' => 'fa-check',
23
                'unicon' => '&#xf00c;' ]
24
    ];
25
26
    const USER_LEVEL = [
27
        1 => [  'text' => 'users.access.local',
28
                'icon' => 'fa-support',
29
                'unicon' => '&#xf1cd;' ],
30
        3 => [  'text' => 'users.access.global',
31
                'icon' => 'fa-globe',
32
                'unicon' => '&#xf0ac;' ],
33
        5 => [  'text' => 'users.access.admin',
34
                'icon' => 'fa-shield',
35
                'unicon' => '&#xf132;' ],
36
        9 => [  'text' => 'users.access.super',
37
                'icon' => 'fa-rocket',
38
                'unicon' => '&#xf135;' ],
39
    ];
40
41
    const SEARCH_CRITERIA = [
42
        'email' => ['email'],
43
        'fullname' => ['firstname', 'lastname'],
44
        'group' => [['group' => 'name']],
45
    ];
46
47
    /**
48
     * The attributes that are mass assignable.
49
     *
50
     * @var array
51
     */
52
    protected $fillable = [
53
        'firstname', 'lastname', 'email', 'password', 'status',
54
    ];
55
56
    /**
57
     * The attributes that should be hidden for arrays.
58
     *
59
     * @var array
60
     */
61
    protected $hidden = [
62
        'password', 'remember_token',
63
    ];
64
65 View Code Duplication
    public function getStatus()
66
    {
67
        if (array_key_exists((int)$this->status, self::USER_STATUS)) {
0 ignored issues
show
Documentation introduced by
The property status 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...
68
            return self::USER_STATUS[(int)$this->status];
0 ignored issues
show
Documentation introduced by
The property status 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...
69
        } else {
70
            return null;
71
        }
72
    }
73
74
    public function getLevel()
75
    {
76
        if (array_key_exists((int)$this->level, self::USER_LEVEL)) {
0 ignored issues
show
Documentation introduced by
The property level 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...
77
            return self::USER_LEVEL[(int)$this->level];
0 ignored issues
show
Documentation introduced by
The property level 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...
78
        } else {
79
            return null;
80
        }
81
    }
82
83
    public function creator()
84
    {
85
        return $this->hasOne('App\User', 'id', 'created_by');
86
    }
87
88
    public function group()
89
    {
90
        return $this->hasOne('App\Group', 'id', 'group_id');
91
    }
92
}
93