Failed Conditions
Push — master ( 7c3864...930f9b )
by Florent
14:15
created

ParameterCheckerManager::check()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4888
c 0
b 0
f 0
cc 5
nc 5
nop 1
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\AuthorizationEndpoint\ParameterChecker;
15
16
use OAuth2Framework\Component\AuthorizationEndpoint\AuthorizationRequest\AuthorizationRequest;
17
use OAuth2Framework\Component\AuthorizationEndpoint\Exception\OAuth2AuthorizationException;
18
use OAuth2Framework\Component\Core\Message\OAuth2Error;
19
20
class ParameterCheckerManager
21
{
22
    /**
23
     * @var ParameterChecker[]
24
     */
25
    private $parameterCheckers = [];
26
27
    public function add(ParameterChecker $parameterChecker): void
28
    {
29
        $this->parameterCheckers[] = $parameterChecker;
30
    }
31
32
    public function check(AuthorizationRequest $authorization): void
33
    {
34
        foreach ($this->parameterCheckers as $parameterChecker) {
35
            try {
36
                $parameterChecker->check($authorization);
37
            } catch (OAuth2AuthorizationException $e) {
38
                throw $e;
39
            } catch (OAuth2Error $e) {
40
                throw new OAuth2AuthorizationException($e->getMessage(), $e->getErrorDescription(), $authorization, $e);
41
            } catch (\Exception $e) {
42
                throw new OAuth2AuthorizationException(OAuth2Error::ERROR_INVALID_REQUEST, $e->getMessage(), $authorization, $e);
43
            }
44
        }
45
    }
46
}
47