Completed
Pull Request — dev (#235)
by Alies
13:26 queued 06:27
created

UserMethod::isAdmin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Models\Auth\Traits\Method;
4
5
/**
6
 * Trait UserMethod.
7
 */
8
trait UserMethod
9
{
10
    /**
11
     * @return mixed
12
     */
13
    public function canChangeEmail()
14
    {
15
        return config('access.users.change_email');
16
    }
17
18
    /**
19
     * @return bool
20
     */
21
    public function canChangePassword()
22
    {
23
        return ! app('session')->has(config('access.socialite_session_name'));
24
    }
25
26
    /**
27
     * @param bool $size
28
     *
29
     * @return bool|\Illuminate\Contracts\Routing\UrlGenerator|mixed|string
30
     * @throws \Illuminate\Container\EntryNotFoundException
31
     */
32
    public function getPicture($size = false)
33
    {
34
        switch ($this->avatar_type) {
35
            case 'gravatar':
36
                if (! $size) {
37
                    $size = config('gravatar.default.size');
38
                }
39
40
                return gravatar()->get($this->email, ['size' => $size]);
0 ignored issues
show
Bug introduced by
The function gravatar was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
                return /** @scrutinizer ignore-call */ gravatar()->get($this->email, ['size' => $size]);
Loading history...
41
42
            case 'storage':
43
                return url('storage/'.$this->avatar_location);
44
        }
45
46
        $social_avatar = $this->providers()->where('provider', $this->avatar_type)->first();
0 ignored issues
show
Bug introduced by
It seems like providers() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
        $social_avatar = $this->/** @scrutinizer ignore-call */ providers()->where('provider', $this->avatar_type)->first();
Loading history...
47
        if ($social_avatar && strlen($social_avatar->avatar)) {
48
            return $social_avatar->avatar;
49
        }
50
51
        return false;
52
    }
53
54
    /**
55
     * @param $provider
56
     *
57
     * @return bool
58
     */
59
    public function hasProvider($provider)
60
    {
61
        foreach ($this->providers as $p) {
62
            if ($p->provider == $provider) {
63
                return true;
64
            }
65
        }
66
67
        return false;
68
    }
69
70
    /**
71
     * @return bool
72
     */
73
    public function isActive()
74
    {
75
        return $this->active;
76
    }
77
78
    /**
79
     * @return bool
80
     */
81
    public function isConfirmed()
82
    {
83
        return $this->confirmed;
84
    }
85
86
    /**
87
     * @return bool
88
     */
89
    public function isPending()
90
    {
91
        return config('access.users.requires_approval') && ! $this->confirmed;
92
    }
93
}
94