Failed Conditions
Push — ng ( 7370de...a36c25 )
by Florent
19:12
created

StateParameterChecker   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B process() 0 15 5
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\AuthorizationEndpoint\ParameterChecker;
15
16
use OAuth2Framework\Component\Server\AuthorizationEndpoint\Authorization;
17
use OAuth2Framework\Component\Server\Core\Response\OAuth2Exception;
18
19
/**
20
 * Class StateParameterChecker.
21
 *
22
 * @see http://tools.ietf.org/html/rfc6749#section-3.1.2
23
 */
24
final class StateParameterChecker implements ParameterChecker
25
{
26
    /**
27
     * @var bool
28
     */
29
    private $stateParameterEnforced = false;
30
31
    /**
32
     * StateParameterChecker constructor.
33
     *
34
     * @param bool $stateParameterEnforced
35
     */
36
    public function __construct(bool $stateParameterEnforced)
37
    {
38
        $this->stateParameterEnforced = $stateParameterEnforced;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function process(Authorization $authorization, callable $next): Authorization
45
    {
46
        try {
47
            if (true === $this->stateParameterEnforced && !$authorization->hasQueryParam('state')) {
48
                throw new \InvalidArgumentException('The parameter "state" is mandatory.');
49
            }
50
            if (true === $authorization->hasQueryParam('state')) {
51
                $authorization = $authorization->withResponseParameter('state', $authorization->getQueryParam('state'));
52
            }
53
54
            return $next($authorization);
55
        } catch (\InvalidArgumentException $e) {
56
            throw new OAuth2Exception(400, OAuth2Exception::ERROR_INVALID_REQUEST, $e->getMessage(), $authorization, $e);
0 ignored issues
show
Documentation introduced by
$authorization is of type object<OAuth2Framework\C...Endpoint\Authorization>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57
        }
58
    }
59
}
60