Completed
Push — 1.0 ( f45751...770e00 )
by Simonas
12:41 queued 10:12
created

Caser   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A camel() 0 4 1
A snake() 0 7 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