Failed Conditions
Push — ng ( 625bbc...a06888 )
by Florent
08:03
created

AbstractInternationalizedRule   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 34
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getInternationalizedParameters() 0 24 6
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
    /**
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