Completed
Pull Request — master (#259)
by Cristian
02:26 queued 11s
created

helpers.php ➔ backpack_middleware()   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_middleware')) {
47
    /**
48
     * Return the key of the middleware used across Backpack.
49
     * That middleware checks if the visitor is an admin.
50
     *
51
     * @param $path
52
     *
53
     * @return string
54
     */
55
    function backpack_middleware()
56
    {
57
        return config('backpack.base.middleware_key', 'admin');
58
    }
59
}
60
61
if (!function_exists('backpack_guard_name')) {
62
    /*
63
     * Returns the name of the guard defined
64
     * by the application config
65
     */
66
    function backpack_guard_name()
67
    {
68
        return config('backpack.base.guard', config('auth.defaults.guard'));
69
    }
70
}
71
72
if (!function_exists('backpack_auth')) {
73
    /*
74
     * Returns the user instance if it exists
75
     * of the currently authenticated admin
76
     * based off the defined guard.
77
     */
78
    function backpack_auth()
79
    {
80
        return \Auth::guard(backpack_guard_name());
81
    }
82
}
83
84
if (!function_exists('backpack_user')) {
85
    /*
86
     * Returns back a user instance without
87
     * the admin guard, however allows you
88
     * to pass in a custom guard if you like.
89
     */
90
    function backpack_user()
91
    {
92
        return backpack_auth()->user();
93
    }
94
}
95