Passed
Push — master ( fd01cd...a8d522 )
by Alexandre
02:26
created

ImplicitFlow   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 66
rs 10
c 0
b 0
f 0
wmc 13

8 Methods

Rating   Name   Duplication   Size   Complexity  
A handleAccessTokenRequest() 0 3 1
A getResponseTypes() 0 3 1
A getUnsupportedResponseModes() 0 3 1
A __construct() 0 3 1
A arrayEqual() 0 7 4
A getGrantTypes() 0 3 1
A handleAuthorizationRequest() 0 19 3
A getDefaultResponseMode() 0 3 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Alexandre
5
 * Date: 18/02/2018
6
 * Time: 18:08
7
 */
8
9
namespace OAuth2\Flows;
10
11
12
use OAuth2\Endpoints\AuthorizationEndpoint;
13
use OAuth2\Endpoints\TokenEndpoint;
14
use OAuth2\Storages\AccessTokenStorageInterface;
15
16
class ImplicitFlow implements FlowInterface
17
{
18
    /**
19
     * @var AccessTokenStorageInterface
20
     */
21
    private $accessTokenStorage;
22
23
    public function __construct(AccessTokenStorageInterface $accessTokenStorage)
24
    {
25
        $this->accessTokenStorage = $accessTokenStorage;
26
    }
27
28
    function getResponseTypes(): 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...
29
    {
30
        return ['token'];
31
    }
32
33
    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...
34
    {
35
        $accessToken = $this->accessTokenStorage->generate(
36
            implode(' ', $authorizationEndpoint->getScopes()),
37
            $authorizationEndpoint->getClient()->getIdentifier(),
38
            $authorizationEndpoint->getResourceOwner()->getIdentifier()
39
        );
40
        $data = [
41
            'access_token' => $accessToken->getToken(),
42
            'token_type' => $accessToken->getType(),
43
        ];
44
        $lifetime = $this->accessTokenStorage->getLifetime();
45
        if (!is_null($lifetime)) {
46
            $data['expires_in'] = $lifetime;
47
        }
48
        if (!$this->arrayEqual($authorizationEndpoint->getScopes(), $requestData['scope'] ?? null)) {
49
            $data['scope'] = implode(' ', $authorizationEndpoint->getScopes());
50
        }
51
        return $data;
52
    }
53
54
    function getDefaultResponseMode(): string
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...
55
    {
56
        return 'fragment';
57
    }
58
59
    function getUnsupportedResponseModes(): 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...
60
    {
61
        return ['query'];
62
    }
63
64
    private function arrayEqual($a, $b)
65
    {
66
        return (
67
            is_array($a)
68
            && is_array($b)
69
            && count($a) == count($b)
70
            && array_diff($a, $b) === array_diff($b, $a)
71
        );
72
    }
73
74
    function getGrantTypes(): 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...
75
    {
76
        return [];
77
    }
78
79
    function handleAccessTokenRequest(TokenEndpoint $tokenEndpoint, 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...
80
    {
81
        return [];
82
    }
83
}