ClientMemoryStorage   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 55
c 0
b 0
f 0
wmc 8
lcom 1
cbo 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getClientDetails() 0 16 2
A getClientScope() 0 8 2
A checkRestrictedGrantType() 0 10 3
1
<?php
2
3
namespace TH\OAuth2\Storage\Memory;
4
5
use OAuth2\Storage\ClientInterface;
6
7
class ClientMemoryStorage implements ClientInterface
8
{
9
    private $clients;
10
11
    public function __construct(Array $clients)
12
    {
13
        $this->clients = $clients;
14
    }
15
16
    /**
17
     * @inherit
18
     */
19
    public function getClientDetails($client_id)
20
    {
21
        if (!array_key_exists($client_id, $this->clients)) {
22
            return null;
23
        }
24
        $default_client_details = [
25
            'client_id'     => $client_id,
26
            'client_secret' => null,
27
            'redirect_uri'  => null,
28
            'scope'         => null,
29
        ];
30
        return array_intersect_key(
31
            array_merge($default_client_details, $this->clients[$client_id]),
32
            $default_client_details
33
        );
34
    }
35
36
    /**
37
     * @inherit
38
     */
39
    public function getClientScope($client_id)
40
    {
41
        $clientDetails = $this->getClientDetails($client_id);
42
        if ($clientDetails === null) {
43
            return null;
44
        }
45
        return $clientDetails['scope'];
46
    }
47
48
    /**
49
     * @inherit
50
     */
51
    public function checkRestrictedGrantType($client_id, $grant_type)
52
    {
53
        if (!array_key_exists($client_id, $this->clients)) {
54
            return null;
55
        }
56
        if (array_key_exists('grant_types', $this->clients[$client_id])) {
57
            return in_array($grant_type, $this->clients[$client_id]);
58
        }
59
        return true;
60
    }
61
}
62