StringModule::snake()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace PhpWinTools\Support;
4
5
/**
6
 * Clone of Str in Laravel.
7
 */
8
class StringModule
9
{
10
    public static function camel(string $string)
11
    {
12
        return lcfirst(self::studly($string));
13
    }
14
15 16
    public static function snake(string $string)
16
    {
17 16
        $string = preg_replace('/\s+/u', '', ucwords($string));
18
19 16
        return strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1_', $string));
20
    }
21
22 5
    public static function studly(string $string)
23
    {
24 5
        $string = ucwords(str_replace(['-', '_'], ' ', $string));
25
26 5
        return str_replace(' ', '', $string);
27
    }
28
}
29