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

getInternationalizedParameters()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.5125
c 0
b 0
f 0
cc 6
eloc 14
nc 5
nop 3
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\DataBag\DataBag;
17
18
abstract class AbstractInternationalizedRule implements Rule
19
{
20
    /**
21
     * @param DataBag       $requestedParameters
22
     * @param string        $base
23
     * @param \Closure|null $closure
24
     *
25
     * @return array
26
     */
27
    protected function getInternationalizedParameters(DataBag $requestedParameters, string $base, ? \Closure $closure): array
28
    {
29
        $result = [];
30
        foreach ($requestedParameters->all() as $k => $v) {
31
            if ($base === $k) {
32
                $closure($k, $v);
33
                $result[$k] = $v;
34
35
                continue;
36
            }
37
38
            $sub = mb_substr($k, 0, mb_strlen($base, '8bit') + 1, '8bit');
39
            if (sprintf('%s#', $base) === $sub && !empty(mb_substr($k, mb_strlen($base, '8bit') + 1, null, '8bit'))) {
40
                if (null !== $closure) {
41
                    $closure($k, $v);
42
                }
43
                $result[$k] = $v;
44
45
                continue;
46
            }
47
        }
48
49
        return $result;
50
    }
51
}
52