Client   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 134
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 11
eloc 20
c 5
b 1
f 0
dl 0
loc 134
ccs 26
cts 26
cp 1
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A clientConfig() 0 3 1
A option() 0 3 1
A secret() 0 3 1
A register() 0 3 1
A keySet() 0 7 2
A clientId() 0 3 1
A provider() 0 3 1
A storage() 0 3 1
A __construct() 0 6 1
A endPoints() 0 3 1
1
<?php
2
3
namespace Parroauth2\Client;
4
5
use Jose\Component\Core\JWKSet;
6
use Parroauth2\Client\EndPoint\EndPoints;
7
use Parroauth2\Client\Extension\ExtensionInterface;
8
use Parroauth2\Client\Provider\ProviderInterface;
9
use Parroauth2\Client\Storage\StorageInterface;
10
11
/**
12
 * The oauth2 client
13
 */
14
class Client implements ClientInterface
15
{
16
    /**
17
     * @var ProviderInterface
18
     */
19
    private $provider;
20
21
    /**
22
     * @var ClientConfig
23
     */
24
    private $clientConfig;
25
26
    /**
27
     * @var EndPoints
28
     */
29
    private $endPoints;
30
31
    /**
32
     * @var StorageInterface
33
     */
34
    private $session;
35
36
37
    /**
38
     * Client constructor.
39
     *
40
     * @param ProviderInterface $provider
41
     * @param ClientConfig $clientConfig
42
     * @param StorageInterface $session
43
     */
44 144
    public function __construct(ProviderInterface $provider, ClientConfig $clientConfig, StorageInterface $session)
45
    {
46 144
        $this->provider = $provider;
47 144
        $this->clientConfig = $clientConfig;
48 144
        $this->endPoints = new EndPoints($provider);
49 144
        $this->session = $session;
50 144
    }
51
52
    /**
53
     * Get the client id
54
     *
55
     * @return string
56
     */
57 67
    public function clientId(): string
58
    {
59 67
        return $this->clientConfig->clientId();
60
    }
61
62
    /**
63
     * Get the client secret.
64
     * May be null on a public client configuration
65
     *
66
     * @return string|null
67
     */
68 42
    public function secret(): ?string
69
    {
70 42
        return $this->clientConfig->secret();
71
    }
72
73
    /**
74
     * Get the client data storage
75
     *
76
     * @return StorageInterface
77
     */
78 42
    public function storage(): StorageInterface
79
    {
80 42
        return $this->session;
81
    }
82
83
    /**
84
     * Get the configuration of the client
85
     *
86
     * @return ClientConfig
87
     */
88 30
    public function clientConfig(): ClientConfig
89
    {
90 30
        return $this->clientConfig;
91
    }
92
93
    /**
94
     * Get the authorization provider
95
     *
96
     * @return ProviderInterface
97
     */
98 144
    public function provider(): ProviderInterface
99
    {
100 144
        return $this->provider;
101
    }
102
103
    /**
104
     * @return EndPoints
105
     */
106 144
    public function endPoints(): EndPoints
107
    {
108 144
        return $this->endPoints;
109
    }
110
111
    /**
112
     * Get the key set for the client
113
     *
114
     * @return JWKSet
115
     */
116 32
    public function keySet(): JWKSet
117
    {
118 32
        if ($jwks = $this->clientConfig->option('jwks')) {
119 2
            return $jwks;
120
        }
121
122 32
        return $this->provider->keySet();
123
    }
124
125
    /**
126
     * Get an option from client or provider
127
     *
128
     * @param string $name The option name
129
     * @param T|null $default The default value to return when not found on client and provider parameters
130
     *
131
     * @return T|null
132
     *
133
     * @template T
134
     */
135 31
    public function option(string $name, $default = null)
136
    {
137 31
        return $this->clientConfig->option($name, $this->provider->metadata($name, $default));
138
    }
139
140
    /**
141
     * Register extension
142
     *
143
     * @param ExtensionInterface $extension
144
     */
145 35
    public function register(ExtensionInterface $extension): void
146
    {
147 35
        $extension->configure($this);
148 35
    }
149
}
150