toCamelCase()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
if (!function_exists("toCamelCase")) {
4
    /**
5
     * @param $str
6
     * @return string
7
     */
8
    function toCamelCase($str)
9
    {
10 21
        $str = ctype_upper($str) ? strtolower($str) : $str;
11
        $str = preg_replace_callback('/_([a-z])/', function ($letter) {
12 21
            return strtoupper($letter[1]);
13 21
        }, $str);
14 21
        return lcfirst(str_replace("_", "", $str));
15
    }
16
}
17
18
if (!function_exists("toSnakeCase")) {
19
    /**
20
     * @param $input
21
     * @return string
22
     */
23
    function toSnakeCase($input)
24
    {
25
26 3
        if (preg_match('/[A-Z]/', $input) === 0) {
27 3
            return $input;
28
        }
29 3
        $pattern = '/([a-z])([A-Z])/';
30
        return  strtolower(preg_replace_callback($pattern, function ($a) {
31 3
            return $a[1] . "_" . strtolower($a[2]);
32 3
        }, $input));
33
    }
34
}
35
36
if (!function_exists('is_object_array')) {
37
    /**
38
     * @param $value
39
     * @return bool
40
     */
41
    function is_object_array($value)
42
    {
43 21
        return count(array_filter(array_keys($value), 'is_string')) > 0;
44
    }
45
}
46