AuthenticateOnceWithBasicAuth   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 71.43%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 7
c 2
b 0
f 0
dl 0
loc 27
ccs 5
cts 7
cp 0.7143
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 16 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
     * @param \Illuminate\Http\Request $request
12
     * @param Closure $next
13
     * @param null $guard
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $guard is correct as it would always require null to be passed?
Loading history...
14
     * @param null $field
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $field is correct as it would always require null to be passed?
Loading history...
15
     * @return mixed
16
     */
17 162
    public function handle($request, Closure $next, $guard = null, $field = null)
18
    {
19 162
        $ipsAuth = env('BASIC_AUTH_IP', '');
20 162
        $ipsAuth = explode(',', $ipsAuth);
21
22
23 162
        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);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->auth->guard($guard)->basic() targeting Illuminate\Auth\SessionGuard::basic() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
28
            }
29
30
        }
31
32 162
        return $next($request);
33
    }
34
35
}