Helpers.php ➔ studly_case()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the overtrue/cuttle.
5
 *
6
 * (c) overtrue <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Overtrue\Cuttle;
13
14
/**
15
 * To camel case.
16
 *
17
 * @param string $str
18
 *
19
 * @return string
20
 */
21
function camel_case(string $str)
0 ignored issues
show
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
22
{
23
    return lcfirst(studly_case($str));
24
}
25
26
/**
27
 * To snake case.
28
 *
29
 * @param string $str
30
 *
31
 * @return string
32
 */
33
function snake_case(string $str)
0 ignored issues
show
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
34
{
35
    if (ctype_lower($str)) {
36
        return $str;
37
    }
38
39
    return mb_strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1_', preg_replace('/\s+/u', '', $str)), 'utf-8');
40
}
41
42
/**
43
 * To studly case.
44
 *
45
 * @param string $str
46
 *
47
 * @return string
48
 */
49
function studly_case(string $str)
0 ignored issues
show
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
50
{
51
    return ucwords(str_replace(['-', '_'], ' ', trim($str)));
52
}
53