SimpleBasicAuth::handle()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 2
dl 0
loc 14
ccs 7
cts 7
cp 1
crap 4
rs 9.7998
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Longman\LaravelLodash\Middlewares;
6
7
use Closure;
8
use Illuminate\Http\Response;
9
10
use function config;
11
use function response;
12
13
class SimpleBasicAuth
14
{
15 4
    public function handle($request, Closure $next)
16
    {
17 4
        $config = config('auth.simple', []);
18
19 4
        if (! empty($config['enabled'])) {
20 3
            if ($request->getUser() !== $config['user'] || $request->getPassword() !== $config['password']) {
21 2
                $header = ['WWW-Authenticate' => 'Basic'];
22
23 2
                return response('You have to supply your credentials to access this resource.', Response::HTTP_UNAUTHORIZED, $header);
24
            }
25
        }
26
27 2
        return $next($request);
28
    }
29
}
30