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

ImplicitFlow::arrayEqual()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 5
nc 4
nop 2
dl 0
loc 7
rs 9.2
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\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
}