User::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 7
rs 9.4286
c 2
b 0
f 1
cc 1
eloc 4
nc 1
nop 1
1
<?php namespace Modules\User\Entities\Sentinel;
2
3
use Cartalyst\Sentinel\Laravel\Facades\Activation;
4
use Cartalyst\Sentinel\Users\EloquentUser;
5
use Illuminate\Support\Facades\Config;
6
use Laracasts\Presenter\PresentableTrait;
7
use Modules\User\Entities\UserInterface;
8
9
class User extends EloquentUser implements UserInterface
10
{
11
    use PresentableTrait;
12
13
    protected $fillable = [
14
        'email',
15
        'password',
16
        'permissions',
17
        'first_name',
18
        'last_name',
19
    ];
20
21
    /**
22
     * {@inheritDoc}
23
     */
24
    protected $loginNames = ['email'];
25
26
    protected $presenter = 'Modules\User\Presenters\UserPresenter';
27
28
    public function __construct(array $attributes = [])
29
    {
30
        parent::__construct($attributes);
31
32
        $this->loginNames = config('asgard.user.users.login-columns');
0 ignored issues
show
Documentation Bug introduced by
It seems like config('asgard.user.users.login-columns') of type * is incompatible with the declared type array of property $loginNames.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
33
        $this->fillable = config('asgard.user.users.fillable');
0 ignored issues
show
Documentation Bug introduced by
It seems like config('asgard.user.users.fillable') of type * is incompatible with the declared type array of property $fillable.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
34
    }
35
36
    /**
37
     * Checks if a user belongs to the given Role ID
38
     * @param  int $roleId
39
     * @return bool
40
     */
41
    public function hasRoleId($roleId)
42
    {
43
        return $this->roles()->whereId($roleId)->count() >= 1;
44
    }
45
46
    /**
47
     * Checks if a user belongs to the given Role Name
48
     * @param  string $name
49
     * @return bool
50
     */
51
    public function hasRoleName($name)
52
    {
53
        return $this->roles()->whereName($name)->count() >= 1;
54
    }
55
56
    /**
57
     * Check if the current user is activated
58
     * @return bool
59
     */
60
    public function isActivated()
61
    {
62
        if (Activation::completed($this)) {
63
            return true;
64
        }
65
66
        return false;
67
    }
68
69
    public function __call($method, $parameters)
70
    {
71
        $class_name = class_basename($this);
72
73
        #i: Convert array to dot notation
74
        $config = implode('.', ['relations', $class_name, $method]);
75
76
        #i: Relation method resolver
77
        if (Config::has($config)) {
78
            $function = Config::get($config);
79
80
            return $function($this);
81
        }
82
83
        #i: No relation found, return the call to parent (Eloquent) to handle it.
84
        return parent::__call($method, $parameters);
85
    }
86
}
87