string.php ➔ snakeToCamelCase()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 8
ccs 3
cts 3
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Equip\String;
4
5
/**
6
 * Convert a snake_case string to a camelCase one.
7
 *
8
 * @param string $snake_string The original snake_case string.
9
 * @param bool $first Whether the first letter should be capitalized
10
 *
11
 * @return string The converted string.
12
 */
13
function snakeToCamelCase($snake_string, $first = false)
14
{
15
    $camel = implode('', array_map(static function($piece) {
16 8
        return ucfirst(strtolower($piece));
17 8
    }, preg_split('/_++/', $snake_string)));
18
19 8
    return $first ? $camel : lcfirst($camel);
20
}
21