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

AuthenticateOnceWithBasicAuth::handle()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 17
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 5.583

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 17
ccs 5
cts 7
cp 0.7143
rs 8.8571
cc 5
eloc 7
nc 4
nop 3
crap 5.583
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
}