functions.php ➔ convertCamelCase()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 10
rs 9.9332
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 = '_') : string
18
{
19
    return trim(preg_replace_callback(
20
        '/[A-Z]/',
21
        function ($match) use ($separator) {
22
            return $separator.strtolower($match[0]);
23
        },
24
        $str
25
    ), $separator);
26
}
27
28
function convertSnakeCase(string $str, $type = 'ucwords') :string
29
{
30
    if ($type === 'ucwords') {
31
        return str_replace(' ', '', ucwords(str_replace('_', ' ', $str)));
32
    }
33
    return lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $str))));
34
}
35