Caser::camel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\ElasticsearchBundle\Mapping;
13
14
use Doctrine\Common\Inflector\Inflector;
15
16
/**
17
 * Utility for string case transformations.
18
 */
19
class Caser
20
{
21
    /**
22
     * Transforms string to camel case (e.g., resultString).
23
     *
24
     * @param string $string Text to transform.
25
     *
26
     * @return string
27
     */
28
    public static function camel($string)
29
    {
30
        return Inflector::camelize($string);
31
    }
32
33
    /**
34
     * Transforms string to snake case (e.g., result_string).
35
     *
36
     * @param string $string Text to transform.
37
     *
38
     * @return string
39
     */
40
    public static function snake($string)
41
    {
42
        $string = preg_replace('#([A-Z\d]+)([A-Z][a-z])#', '\1_\2', self::camel($string));
43
        $string = preg_replace('#([a-z\d])([A-Z])#', '\1_\2', $string);
44
45
        return strtolower(strtr($string, '-', '_'));
46
    }
47
}
48