Failed Conditions
Push — ng ( a2b1ac...8ea883 )
by Florent
04:25
created

UserParametersRule::handle()   D

Complexity

Conditions 9
Paths 15

Size

Total Lines 31
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 4.909
c 0
b 0
f 0
cc 9
eloc 21
nc 15
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\ClientRule;
15
16
use OAuth2Framework\Component\Core\Client\ClientId;
17
use OAuth2Framework\Component\Core\DataBag\DataBag;
18
19
class UserParametersRule implements Rule
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function handle(ClientId $clientId, DataBag $commandParameters, DataBag $validatedParameters, callable $next): DataBag
25
    {
26
        if ($commandParameters->has('require_auth_time')) {
27
            $require_auth_time = $commandParameters->get('require_auth_time');
28
            if (!is_bool($require_auth_time)) {
29
                throw new \InvalidArgumentException('The parameter "require_auth_time" must be a boolean.');
30
            }
31
            $validatedParameters = $validatedParameters->with('require_auth_time', $require_auth_time);
32
        }
33
        if ($commandParameters->has('default_max_age')) {
34
            $default_max_age = $commandParameters->get('default_max_age');
35
            if (!is_int($default_max_age) || $default_max_age < 0) {
36
                throw new \InvalidArgumentException('The parameter "default_max_age" must be a positive integer.');
37
            }
38
            $validatedParameters = $validatedParameters->with('default_max_age', $default_max_age);
39
        }
40
        if ($commandParameters->has('default_acr_values')) {
41
            $default_acr_values = $commandParameters->get('default_acr_values');
42
            if (!is_array($default_acr_values)) {
43
                throw new \InvalidArgumentException('The parameter "default_acr_values" must be an array of strings.');
44
            }
45
            array_map(function ($default_acr_value) {
46
                if (!is_string($default_acr_value)) {
47
                    throw new \InvalidArgumentException('The parameter "default_acr_values" must be an array of strings.');
48
                }
49
            }, $default_acr_values);
50
            $validatedParameters = $validatedParameters->with('default_acr_values', $default_acr_values);
51
        }
52
53
        return $next($clientId, $commandParameters, $validatedParameters);
54
    }
55
}
56