Completed
Branch master (f8a0b6)
by Arnold
06:06
created

case_functions.php ➔ studlycase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 5
ccs 2
cts 2
cp 1
crap 1
rs 9.4285
1
<?php
2
3
namespace Jasny;
4
5
/**
6
 * Turn a sentence, camelCase, snake_case or kabab-case into camelCase
7
 *
8
 * @param string $string
9
 * @return string
10
 */
11
function camelcase($string)
12
{
13 1
    $sentence = preg_replace('/[\W_]+/', ' ', $string);
14 1
    return lcfirst(str_replace(' ', '', ucwords($sentence)));
15
}
16
17
/**
18
 * Turn a sentence, camelCase, snake_case or kabab-case into StudlyCase
19
 *
20
 * @param string $string
21
 * @return string
22
 */
23
function studlycase($string)
24
{
25 1
    $sentence = preg_replace('/[\W_]+/', ' ', $string);
26 1
    return str_replace(' ', '', ucwords($sentence));
27
}
28
29
/**
30
 * Turn a sentence, camelCase, StudlyCase or kabab-case into snake_case
31
 *
32
 * @param string $string
33
 * @return string
34
 */
35
function snakecase($string)
36
{
37 1
    $sentence = strtolower(preg_replace('/([a-z0-9])([A-Z])/', '$1 $2', $string));
38 1
    return preg_replace('/[\W\_]+/', '_', $sentence);
39
}
40
41
/**
42
 * Turn a sentence, camelCase, StudlyCase or snake_case into kabab-case
43
 *
44
 * @param string $string
45
 * @return string
46
 */
47
function kababcase($string)
48
{
49 1
    $sentence = strtolower(preg_replace('/([a-z0-9])([A-Z])/', '$1 $2', $string));
50 1
    return preg_replace('/[\W\_]+/', '-', $sentence);
51
}
52
53
/**
54
 * Turn StudlyCase, camelCase, snake_case or kabab-case into a sentence.
55
 *
56
 * @param string $string
57
 * @return string
58
 */
59
function uncase($string)
60
{
61 1
    $snake = strtolower(preg_replace('/([a-z0-9])([A-Z])/', '$1 $2', $string));
62 1
    $sentence = preg_replace('/[-_\s]+/', ' ', $snake);
63 1
    if (ctype_upper($string[0])) $sentence = ucfirst($sentence);
64
    
65 1
    return $sentence;
66
}
67