Failed Conditions
Push — ng ( 977556...d85ce7 )
by Florent
03:52
created

RequestUriRule   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 13 4
B checkAllUris() 0 11 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\Rule;
15
16
use OAuth2Framework\Component\ClientRule\Rule;
17
use OAuth2Framework\Component\Core\Client\ClientId;
18
use OAuth2Framework\Component\Core\DataBag\DataBag;
19
20
class RequestUriRule implements Rule
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function handle(ClientId $clientId, DataBag $commandParameters, DataBag $validatedParameters, callable $next): DataBag
26
    {
27
        $validatedParameters = $next($clientId, $commandParameters, $validatedParameters);
28
        if (!$validatedParameters->has('response_types') || empty($validatedParameters->get('response_types'))) {
29
            return $validatedParameters;
30
        }
31
        if ($commandParameters->has('request_uris')) {
32
            $this->checkAllUris($commandParameters->get('request_uris'));
33
            $validatedParameters = $validatedParameters->with('request_uris', $commandParameters->get('request_uris'));
34
        }
35
36
        return $validatedParameters;
37
    }
38
39
    /**
40
     * @param mixed $value
41
     */
42
    private function checkAllUris($value)
43
    {
44
        if (!is_array($value)) {
45
            throw new \InvalidArgumentException('The parameter "request_uris" must be a list of URI.');
46
        }
47
        foreach ($value as $redirectUri) {
48
            if (!is_string($redirectUri) || !filter_var($redirectUri, FILTER_VALIDATE_URL)) {
49
                throw new \InvalidArgumentException('The parameter "request_uris" must be a list of URI.');
50
            }
51
        }
52
    }
53
}
54