Completed
Pull Request — master (#165)
by Cristian
04:50
created

helpers.php ➔ backpack_guard_name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
if (!function_exists('backpack_url')) {
4
    /**
5
     * Appends the configured backpack prefix and returns
6
     * the URL using the standard Laravel helpers.
7
     *
8
     * @param $path
9
     *
10
     * @return string
11
     */
12
    function backpack_url($path = null)
13
    {
14
        $path = !$path || (substr($path, 1, 1) == '/') ? $path : '/'.$path;
15
16
        return url(config('backpack.base.route_prefix', 'admin').$path);
17
    }
18
}
19
20
if (!function_exists('backpack_avatar')) {
21
    /**
22
     * Returns the avatar URL of a user.
23
     *
24
     * @param $user
25
     *
26
     * @return string
27
     */
28
    function backpack_avatar_url($user)
29
    {
30
        switch (config('backpack.base.avatar_type')) {
31
            case 'gravatar':
32
                return Gravatar::fallback('https://placehold.it/160x160/00a65a/ffffff/&text='.$user->name[0])->get($user->email);
33
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
34
35
            case 'placehold':
36
                return 'https://placehold.it/160x160/00a65a/ffffff/&text='.$user->name[0];
37
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
38
39
            default:
40
                return $user->{config('backpack.base.avatar_type')};
41
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
42
        }
43
    }
44
}
45
46
if (!function_exists('backpack_guard_name')) {
47
    /*
48
     * Returns the name of the guard defined
49
     * by the application config
50
     */
51
    function backpack_guard_name()
52
    {
53
        return config('backpack.base.guard', config('auth.defaults.guard'));
54
    }
55
}
56
57
if (!function_exists('backpack_auth')) {
58
    /*
59
     * Returns the user instance if it exists
60
     * of the currently authenticated admin
61
     * based off the defined guard.
62
     */
63
    function backpack_auth()
64
    {
65
        return \Auth::guard(backpack_guard_name());
66
    }
67
}
68
69
if (!function_exists('backpack_user')) {
70
    /*
71
     * Returns back a user instance without
72
     * the admin guard, however allows you
73
     * to pass in a custom guard if you like.
74
     */
75
    function backpack_user()
76
    {
77
        return backpack_auth()->user();
78
    }
79
}
80