ChangeCase   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A camelToSnake() 0 4 1
A snakeToCamel() 0 7 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