Failed Conditions
Push — ng ( 3a2d0f...7d4708 )
by Florent
04:04
created

RequestUriRule::handle()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 3
nop 4
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\ClientRegistrationEndpoint\Rule;
15
16
use OAuth2Framework\Component\Server\Core\Client\ClientId;
17
use OAuth2Framework\Component\Server\Core\DataBag\DataBag;
18
19
final 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