Completed
Pull Request — master (#87)
by Owen
02:01
created

BackpackAdminGuard::handle()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 9
Ratio 64.29 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
eloc 7
nc 4
nop 2
dl 9
loc 14
rs 8.8571
c 1
b 0
f 1
1
<?php
2
3
namespace Backpack\Base\app\Http\Middleware;
4
5
use Closure;
6
7
class BackpackAdminGuard
8
{
9
    /**
10
     * Handle an incoming request.
11
     *
12
     * @param \Illuminate\Http\Request $request
13
     * @param \Closure                 $next
14
     *
15
     * @return mixed
16
     */
17
    public function handle($request, Closure $next)
18
    {
19 View Code Duplication
        if (config('backpack.base.separate_admin_session')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
            if (!\Auth::guard(config('backpack.base.admin_guard.name'))->check()) {
21
                if ($request->ajax() || $request->wantsJson()) {
22
                    return response(trans('backpack::base.unauthorized'), 401);
0 ignored issues
show
Bug introduced by
It seems like trans('backpack::base.unauthorized') targeting trans() can also be of type object<Symfony\Component...on\TranslatorInterface>; however, response() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
23
                }
24
25
                return redirect(config('backpack.base.route_prefix').'/login');
26
            }
27
        }
28
29
        return $next($request);
30
    }
31
}
32