Completed
Push — master ( 5dab40...ca534d )
by Maxime
120:18 queued 114:35
created

AuthenticateOnceWithBasicAuth   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 71.43%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 3
dl 0
loc 30
ccs 5
cts 7
cp 0.7143
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 17 5
1
<?php namespace Distilleries\Expendable\Http\Middleware;
2
3
use Closure;
4
use Illuminate\Auth\Middleware\AuthenticateWithBasicAuth;
5
6
class AuthenticateOnceWithBasicAuth extends AuthenticateWithBasicAuth {
7
8
9
    /**
10
     * Handle an incoming request.
11
     *
12
     * @param  \Illuminate\Http\Request  $request
13
     * @param  \Closure  $next
14
     * @param  string|null  $guard
15
     * @return mixed
16
     */
17 300
    public function handle($request, Closure $next, $guard = null)
18
    {
19 300
        $ipsAuth = env('BASIC_AUTH_IP','');
20 300
        $ipsAuth = explode(',',$ipsAuth);
21
22
23 300
        if (env('BASIC_AUTH',false) == true)
24
        {
25
            if(empty($ipsAuth) || !in_array($request->ip(),$ipsAuth))
26
            {
27
                return $this->auth->guard($guard)->basic() ?: $next($request);
28
            }
29
30
        }
31
32 300
        return $next($request);
33
    }
34
35
}