Completed
Push — master ( ea590f...4351c0 )
by Maciej
05:54
created

StringHelper::noFirstCamelCase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 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
    public static function noFirstCamelCase($str)
23
    {
24
        $str = self::camelCase($str);
25
        $str = lcfirst($str);
26
27
        return $str;
28
    }
29
30
    /**
31
     * @param $str
32
     *
33
     * @return string
34
     */
35
    public static function camelCase($str)
36
    {
37
        $str = strtolower($str);
38
        $str = preg_replace('/[^a-z0-9]+/', ' ', $str);
39
        $str = trim($str);
40
        $str = ucwords($str);
41
        $str = str_replace(' ', '', $str);
42
43
        return $str;
44
    }
45
46
    /**
47
     * Converts camel case to snake case.
48
     *
49
     * @param $string
50
     *
51
     * @return string
52
     */
53
    public static function camelCaseToSnakeCase($string)
54
    {
55
        return strtolower(preg_replace(['/([a-z\d])([A-Z])/', '/([^_])([A-Z][a-z])/'], '$1_$2', $string));
56
    }
57
}
58