Passed
Branch master (30ae21)
by Gabor
03:15
created

CamelCaseToUnderScoreTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 20
c 0
b 0
f 0
wmc 3
lcom 0
cbo 0
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A camelCaseToUnderscore() 0 11 3
1
<?php
2
/**
3
 * WebHemi.
4
 *
5
 * PHP version 5.6
6
 *
7
 * @copyright 2012 - 2016 Gixx-web (http://www.gixx-web.com)
8
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
9
 *
10
 * @link      http://www.gixx-web.com
11
 */
12
namespace WebHemi\Form\Traits;
13
14
/**
15
 * Class CamelCaseToUnderScoreTrait.
16
 */
17
trait CamelCaseToUnderScoreTrait
18
{
19
    /**
20
     * Converts CamelCase text to under_score equivalent.
21
     *
22
     * @param $input
23
     * @return string
24
     */
25 2
    protected function camelCaseToUnderscore($input)
26
    {
27 2
        preg_match_all('/([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)/', $input, $matches);
28 2
        $return = $matches[0];
29
30 2
        foreach ($return as &$match) {
31 2
            $match = $match == strtoupper($match) ? strtolower($match) : lcfirst($match);
32 2
        }
33
34 2
        return implode('_', $return);
35
    }
36
}
37