AuthorizationEndPoint::uri()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 0
crap 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