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

ParameterCheckerManager   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A check() 0 14 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\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