Authentication   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 24
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 14 2
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Xervice\Service\Middleware\Security;
6
7
8
use Closure;
9
use DataProvider\ApiAuthenticationFailedDataProvider;
0 ignored issues
show
Bug introduced by
The type DataProvider\ApiAuthenticationFailedDataProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Illuminate\Http\Request;
11
use Xervice\Service\Application\Response\ApiResponse;
12
use Xervice\Service\Middleware\AbstractMiddleware;
13
14
/**
15
 * @method \Xervice\Service\ServiceFactory getFactory()
16
 */
17
class Authentication extends AbstractMiddleware
18
{
19
    /**
20
     * @param \Illuminate\Http\Request $request
21
     * @param \Closure $next
22
     *
23
     * @return mixed|\Xervice\Service\Middleware\Security\Response\SecurityUnauthorizedResponse
24
     * @throws \Core\Locator\Dynamic\ServiceNotParseable
25
     * @throws \Xervice\Config\Exception\ConfigNotFound
26
     */
27
    public function handle(Request $request, Closure $next)
28
    {
29
        $authenticator = $this->getFactory()->createAuthenticator();
30
        if (!$authenticator->isAuth($request)) {
31
            $response = $this->getFactory()->createSecurityUnauthorizedResponse();
32
            $response->setSecurityResponse($request);
33
34
            return response()->json(
35
                $response->getData(),
36
                401
37
            );
38
        }
39
40
        return $next($request);
41
    }
42
43
}