Passed
Push — master ( c97e91...9a636e )
by Alexandre
01:52
created

AuthorizationCodeFlow   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createAuthorizationCode() 0 8 1
A handleAuthorizationRequest() 0 13 3
A saveAndGetResult() 0 4 1
A __construct() 0 3 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Alexandre
5
 * Date: 10/03/2018
6
 * Time: 17:40
7
 */
8
9
namespace OAuth2\Extensions\OpenID\Flows;
10
11
12
use OAuth2\Credentials\AuthorizationCodeInterface;
13
use OAuth2\Endpoints\AuthorizationEndpoint;
14
use OAuth2\Exceptions\OAuthException;
15
use OAuth2\ResponseTypes\ResponseTypeInterface;
16
use OAuth2\Storages\AuthorizationCodeStorageInterface;
17
18
class AuthorizationCodeFlow extends \OAuth2\Flows\AuthorizationCodeFlow
19
{
20
    public function __construct(AuthorizationCodeStorageInterface $authorizationCodeStorage)
21
    {
22
        parent::__construct($authorizationCodeStorage);
0 ignored issues
show
Bug introduced by
The call to OAuth2\Flows\AuthorizationCodeFlow::__construct() has too few arguments starting with accessTokenStorage. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
        parent::/** @scrutinizer ignore-call */ 
23
                __construct($authorizationCodeStorage);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
23
    }
24
25
    /**
26
     * @param AuthorizationEndpoint $authorizationEndpoint
27
     * @param array $requestData
28
     * @return array
29
     * @throws OAuthException
30
     */
31
    function handleAuthorizationRequest(AuthorizationEndpoint $authorizationEndpoint, array $requestData): array
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
32
    {
33
        $authorizationCode = $this->createAuthorizationCode($authorizationEndpoint);
34
        if (in_array('openid', $authorizationEndpoint->getScopes())) {
35
            if (empty($requestData['redirect_uri'])) {
36
                throw new OAuthException('invalid_request', 'The request is missing the required parameter redirect_uri.',
37
                    'https://tools.ietf.org/html/rfc6749#section-4.1');
38
            }
39
40
41
            $requestData['nonce'];
42
        }
43
        return $this->saveAndGetResult($authorizationCode);
44
    }
45
46
    protected function createAuthorizationCode(AuthorizationEndpoint $authorizationEndpoint)
47
    {
48
        return $this->authorizationCodeStorage->create(
49
            implode(' ', $authorizationEndpoint->getScopes()),
50
            $authorizationEndpoint->getClient()->getIdentifier(),
51
            $authorizationEndpoint->getResourceOwner()->getIdentifier(),
52
            $requestData['scope'] ?? null,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $requestData seems to never exist and therefore isset should always be false.
Loading history...
53
            $requestData['redirect_uri'] ?? null
54
        );
55
    }
56
57
    protected function saveAndGetResult(AuthorizationCodeInterface $authorizationCode)
58
    {
59
        $this->authorizationCodeStorage->save($authorizationCode);
60
        return ['code' => $authorizationCode->getCode()];
61
    }
62
63
}