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

ImplicitFlow::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
}