Helper::camelCaseToUnderscore()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
rs 9.4286
cc 3
eloc 8
nc 3
nop 1
1
<?php
2
3
namespace Saxulum\Crud\Util;
4
5
class Helper
6
{
7
    /**
8
     * @param string $input
9
     *
10
     * @return string
11
     */
12
    public static function camelCaseToUnderscore($input)
13
    {
14
        $output = '';
15
        $outputParts = preg_split('/(?=[\p{Lu}])/', $input);
16
        foreach ($outputParts as $outputPart) {
17
            if ($outputPart) {
18
                $output .= rtrim($outputPart, '_').'_';
19
            }
20
        }
21
22
        $output = mb_strtolower(rtrim($output, '_'));
23
24
        return $output;
25
    }
26
}
27