StringHelper::camelCaseToSnakeCase()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Created by Maciej Paprocki for Bureau-VA.
4
 * Date: 18/02/2016
5
 * Project Name: MaciekPaprocki\WordpressGuzzle
6
 * Time: 12:12.
7
 */
8
namespace BureauVa\WordpressGuzzle\Helper;
9
10
/**
11
 * Class StringHelper.
12
 */
13
class StringHelper
14
{
15
    /**
16
     * converts to camel case. Shamefully stolen from.
17
     *
18
     * @param $str
19
     *
20
     * @return string
21
     */
22 2
    public static function noFirstCamelCase($str)
23
    {
24 2
        $str = self::camelCase($str);
25 2
        $str = lcfirst($str);
26
27 2
        return $str;
28
    }
29
30
    /**
31
     * @param $str
32
     *
33
     * @return string
34
     */
35 4
    public static function camelCase($str)
36
    {
37 4
        $str = strtolower($str);
38 4
        $str = preg_replace('/[^a-z0-9]+/', ' ', $str);
39 4
        $str = trim($str);
40 4
        $str = ucwords($str);
41 4
        $str = str_replace(' ', '', $str);
42
43 4
        return $str;
44
    }
45
46
    /**
47
     * Converts camel case to snake case.
48
     *
49
     * @param $string
50
     *
51
     * @return string
52
     */
53 2
    public static function camelCaseToSnakeCase($string)
54
    {
55 2
        return strtolower(preg_replace(['/([a-z\d])([A-Z])/', '/([^_])([A-Z][a-z])/'], '$1_$2', $string));
56
    }
57
}
58