ApiAuthenticator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 22
dl 0
loc 54
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A authenticate() 0 32 4
1
<?php
2
3
4
namespace Xervice\Api\Business\Model\Authenticator;
5
6
7
use DataProvider\ApiAuthDataProvider;
0 ignored issues
show
Bug introduced by
The type DataProvider\ApiAuthDataProvider 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...
8
use DataProvider\AuthenticatorDataProvider;
0 ignored issues
show
Bug introduced by
The type DataProvider\AuthenticatorDataProvider 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...
9
use Symfony\Component\HttpFoundation\Request;
10
use Xervice\Api\Business\Exception\AuthorizationException;
11
use Xervice\Security\Business\Exception\SecurityException;
12
use Xervice\Security\Business\SecurityFacade;
13
14
class ApiAuthenticator implements ApiAuthenticatorInterface
15
{
16
    /**
17
     * @var \Xervice\Security\Business\SecurityFacade
18
     */
19
    private $securityFacade;
20
21
    /**
22
     * ApiAuthenticator constructor.
23
     *
24
     * @param \Xervice\Security\Business\SecurityFacade $securityFacade
25
     */
26 3
    public function __construct(SecurityFacade $securityFacade)
27
    {
28 3
        $this->securityFacade = $securityFacade;
29 3
    }
30
31
    /**
32
     * @param \Symfony\Component\HttpFoundation\Request $request
33
     *
34
     * @throws \Xervice\Api\Business\Exception\AuthorizationException
35
     */
36 3
    public function authenticate(Request $request)
37
    {
38 3
        $authHeader = $request->headers->get('authorization');
39
40 3
        if (!$authHeader) {
41 1
            throw new AuthorizationException('No HTTP_Authorization header found');
42
        }
43
44 2
        $authParts = explode(' ', $authHeader);
45
46 2
        if (count($authParts) < 2) {
47 1
            throw new AuthorizationException(
48 1
                sprintf(
49 1
                    'Wrong structure for HTTP_Authorization header %s',
50 1
                    $authHeader
51
                )
52
            );
53
        }
54
55 1
        $apiAuth = new ApiAuthDataProvider();
56 1
        $apiAuth->setAuthHeader($authHeader);
57
58 1
        $auth = new AuthenticatorDataProvider();
59 1
        $auth->setAuthData($apiAuth);
60
61
        try {
62 1
            $this->securityFacade->authenticate($authParts[0], $auth);
63 1
        } catch (SecurityException $exception) {
64 1
            throw new AuthorizationException(
65 1
                $exception->getMessage(),
66 1
                0,
67 1
                $exception
68
            );
69
        }
70
    }
71
}