Completed
Push — master ( cb5dd1...e02510 )
by Iqbal
09:00
created

code_style.php ➔ convert_to_camel_case()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 1
b 0
f 1
1
<?php
2
/*
3
 * This file is part of the Borobudur-DependencyInjection package.
4
 *
5
 * (c) Hexacodelabs <http://hexacodelabs.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
if (!function_exists('convert_to_snake_case')) {
12
    /**
13
     * Convert camel case style to snake case (underscore).
14
     *
15
     * @param string $camelCase
16
     *
17
     * @return string
18
     *
19
     * @author      Iqbal Maulana <[email protected]>
20
     * @created     8/13/15
21
     */
22
    function convert_to_snake_case($camelCase)
23
    {
24
        preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[0-9A-Za-z][a-z0-9]+)!', $camelCase, $matches);
25
26
        return implode('_', array_map('strtolower', $matches[0]));
27
    }
28
}
29
30
if (!function_exists('convert_to_camel_case')) {
31
    /**
32
     * Convert snake case (underscore) style to camel case.
33
     *
34
     * @param string $snakeCase
35
     *
36
     * @return string
37
     *
38
     * @author      Iqbal Maulana <[email protected]>
39
     * @created     9/8/15
40
     */
41
    function convert_to_camel_case($snakeCase)
42
    {
43
        return lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $snakeCase))));
44
    }
45
}
46