Completed
Push — master ( 64cd9f...411f65 )
by Alexandre
02:13
created

ImplicitFlow   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 11

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getResponseTypes() 0 3 1
A getUnsupportedResponseModes() 0 3 1
A __construct() 0 3 1
A arrayEqual() 0 7 4
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\Storages\AccessTokenStorageInterface;
14
15
class ImplicitFlow implements FlowInterface
16
{
17
    /**
18
     * @var AccessTokenStorageInterface
19
     */
20
    private $accessTokenStorage;
21
22
    public function __construct(AccessTokenStorageInterface $accessTokenStorage)
23
    {
24
        $this->accessTokenStorage = $accessTokenStorage;
25
    }
26
27
    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...
28
    {
29
        return ['token'];
30
    }
31
32
    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...
33
    {
34
        $accessToken = $this->accessTokenStorage->generate(
35
            implode(' ', $authorizationEndpoint->getScopes()),
36
            $authorizationEndpoint->getClient()->getIdentifier(),
37
            $authorizationEndpoint->getResourceOwner()->getIdentifier()
38
        );
39
        $data = [
40
            'access_token' => $accessToken->getToken(),
41
            'token_type' => $accessToken->getType(),
42
        ];
43
        $lifetime = $this->accessTokenStorage->getLifetime();
44
        if (!is_null($lifetime)) {
45
            $data['expires_in'] = $lifetime;
46
        }
47
        if (!$this->arrayEqual($authorizationEndpoint->getScopes(), $requestData['scope'] ?? null)) {
48
            $data['scope'] = implode(' ', $authorizationEndpoint->getScopes());
49
        }
50
        return $data;
51
    }
52
53
    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...
54
    {
55
        return 'fragment';
56
    }
57
58
    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...
59
    {
60
        return ['query'];
61
    }
62
63
    private function arrayEqual($a, $b)
64
    {
65
        return (
66
            is_array($a)
67
            && is_array($b)
68
            && count($a) == count($b)
69
            && array_diff($a, $b) === array_diff($b, $a)
70
        );
71
    }
72
}