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

camelCaseToUnderscore()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
ccs 7
cts 7
cp 1
rs 9.4285
cc 3
eloc 6
nc 3
nop 1
crap 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