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