AuthorizationEndPoint   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 10
c 1
b 0
f 0
dl 0
loc 44
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A scope() 0 8 2
A nonce() 0 7 2
A uri() 0 8 2
1
<?php
2
3
namespace Parroauth2\Client\OpenID\EndPoint;
4
5
use Base64Url\Base64Url;
6
use Parroauth2\Client\EndPoint\Authorization\AuthorizationEndPoint as BaseAuthorizationEndPoint;
7
8
/**
9
 * Authorization endpoint for OpenID Connect provider
10
 *
11
 * @see https://openid.net/specs/openid-connect-core-1_0.html#AuthorizationEndpoint
12
 */
13
class AuthorizationEndPoint extends BaseAuthorizationEndPoint
14
{
15
    /**
16
     * {@inheritdoc}
17
     *
18
     * @psalm-mutation-free
19
     */
20 17
    public function scope(array $scopes): BaseAuthorizationEndPoint
21
    {
22 17
        if (!in_array('openid', $scopes)) {
23 14
            array_unshift($scopes, 'openid');
24
        }
25
26
        /** @var static */
27 17
        return BaseAuthorizationEndPoint::scope($scopes);
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 27
    public function uri(): string
34
    {
35 27
        if (isset($this->parameters()['scope'])) {
36 27
            return parent::uri();
37
        }
38
39
        // Add the scope parameter if not yet set
40 10
        return $this->set('scope', 'openid')->uri();
41
    }
42
43
    /**
44
     * Set the nonce
45
     *
46
     * @param string|null $nonce The nonce, or null to generate it
47
     *
48
     * @return static
49
     */
50 3
    public function nonce(?string $nonce = null): self
51
    {
52 3
        if ($nonce === null) {
53 3
            $nonce = Base64Url::encode(random_bytes(32));
54
        }
55
56 3
        return $this->set('nonce', $nonce);
57
    }
58
}
59