ChangeCase::snakeToCamel()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 2
crap 2
1
<?php
2
/*
3
 * This file is part of the Bushido\Foundation package.
4
 *
5
 * (c) Wojciech Nowicki <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE.md
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Bushido\Foundation\Helpers;
12
13
class ChangeCase
14
{
15 75
    public static function camelToSnake(string $string): string
16
    {
17 75
        $string[0] = strtolower($string[0]);
18 75
        return strtolower((string) preg_replace("/([A-Z])/", "_$1", $string));
19
    }
20
21 33
    public static function snakeToCamel(string $string, bool $firstLowercase = false): string
22
    {
23 33
        $rtn = str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($string))));
24 33
        if ($firstLowercase) {
25 6
            $rtn[0] = strtolower($rtn[0]);
26
        }
27 33
        return $rtn;
28
    }
29
}
30