Failed Conditions
Push — ng ( ede6c5...efffe8 )
by Florent
11:50
created

NonceParameterChecker   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 19
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 13 4
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 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\Server\OpenIdConnect;
15
16
use OAuth2Framework\Component\Server\AuthorizationEndpoint\Authorization;
17
use OAuth2Framework\Component\Server\AuthorizationEndpoint\Exception\OAuth2AuthorizationException;
18
use OAuth2Framework\Component\Server\AuthorizationEndpoint\ParameterChecker\ParameterChecker;
19
use OAuth2Framework\Component\Server\Core\Exception\OAuth2Exception;
20
21
/**
22
 * Class NonceParameterChecker.
23
 */
24
final class NonceParameterChecker implements ParameterChecker
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function check(Authorization $authorization): Authorization
30
    {
31
        try {
32
            $authorization = $authorization;
0 ignored issues
show
Bug introduced by
Why assign $authorization to itself?

This checks looks for cases where a variable has been assigned to itself.

This assignement can be removed without consequences.

Loading history...
33
            if (false !== strpos($authorization->getQueryParam('response_type'), 'id_token') && !$authorization->hasQueryParam('nonce')) {
34
                throw new \InvalidArgumentException('The parameter "nonce" is mandatory when the response type "id_token" is used.');
35
            }
36
37
            return $authorization;
38
        } catch (\InvalidArgumentException $e) {
39
            throw new OAuth2AuthorizationException(400, OAuth2Exception::ERROR_INVALID_REQUEST, $e->getMessage(), $authorization, $e);
40
        }
41
    }
42
}
43