Failed Conditions
Push — master ( b5a0b4...819484 )
by Florent
08:00
created

getInternationalizedParameters()   A

Complexity

Conditions 6
Paths 5

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

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