Test Failed
Push — master ( c284ba...f1f4ff )
by Mehmet
02:24
created

functions.php ➔ convertSnakeCase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace MerchantSafeUnipay;
5
6
function filter(array $filterKeys, array $arrayData)
7
{
8
    $filteredData = [];
9
    foreach ($arrayData as $key => $value) {
10
        if (in_array($key, $filterKeys, true)) {
11
            $filteredData[$key] = $value;
12
        }
13
    }
14
    return $filteredData;
15
}
16
17
function convertCamelCase(string $str, string $separator = '_')
18
{
19
    return preg_replace_callback(
20
        '/[A-Z]/',
21
        function ($match) use ($separator) {
22
            return $separator.strtolower($match[0]);
23
        },
24
        $str
25
    );
26
}
27
28
function convertSnakeCase(string $str)
29
{
30
    return str_replace(' ','', ucwords(str_replace('_', ' ', $str)));
31
}
32