Completed
Pull Request — master (#259)
by Cristian
02:42
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