NonceParameterChecker   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 8 4
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2019 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\Component\OpenIdConnect\ParameterChecker;
15
16
use InvalidArgumentException;
17
use OAuth2Framework\Component\AuthorizationEndpoint\AuthorizationRequest\AuthorizationRequest;
18
use OAuth2Framework\Component\AuthorizationEndpoint\ParameterChecker\ParameterChecker;
19
20
final class NonceParameterChecker implements ParameterChecker
21
{
22
    public function check(AuthorizationRequest $authorization): void
23
    {
24
        if (!$authorization->hasQueryParam('response_type')) {
25
            throw new InvalidArgumentException('The parameter "response_type" is mandatory.');
26
        }
27
        $response_type = explode(' ', $authorization->getQueryParam('response_type'));
28
        if (\in_array('id_token', $response_type, true) && !$authorization->hasQueryParam('nonce')) {
29
            throw new InvalidArgumentException('The parameter "nonce" is mandatory when the response type "id_token" is used.');
30
        }
31
    }
32
}
33