helpers.php ➔ camel_case()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Htsl\Helper;
4
5
/**
6
 * Change 'abc_def-ghi jkh' to 'abcDefGhiJkh'.
7
 *
8
 * @param  string $input
9
 *
10
 * @return string
11
 */
12
function camel_case( string$input ):string
13
{
14
	return lcfirst(studly_case($input));
15
}
16
17
/**
18
 * Change 'abc_def-ghi jkh' to 'AbcDefGhiJkh'.
19
 *
20
 * @param  string $input
21
 *
22
 * @return string
23
 */
24
function studly_case( string$input ):string
25
{
26
	return str_replace(' ','',ucwords(str_replace(['-', '_'], ' ', $input)));
27
}
28
29
/**
30
 * Change 'AbcDEFGhiJkh' or 'abcDefGhiJkh' to 'abc_def_ghi_jkh'.
31
 *
32
 * @param  string $input
33
 *
34
 * @return string
35
 */
36
function snake_case( string$input ):string
37
{
38
	return strtolower(preg_replace('/(?<=[^A-Z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][^A-Z])/','_',$input));
39
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
40