Completed
Pull Request — master (#87)
by Cristian
08:06
created

BackpackAuthGuard   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 36 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 9
loc 25
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 9 14 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Backpack\Base\app\Http\Middleware;
4
5
use Closure;
6
7
class BackpackAuthGuard
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);
23
                }
24
25
                return redirect(config('backpack.base.route_prefix').'/login');
26
            }
27
        }
28
29
        return $next($request);
30
    }
31
}
32