StringUtil::classToSnakeCase()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 9
ccs 7
cts 7
cp 1
crap 2
rs 10
1
<?php
2
3
namespace MediaMonks\RestApi\Util;
4
5
class StringUtil
6
{
7
    /**
8
     * @param $class
9
     * @param string $trim
10
     * @return string
11
     */
12 6
    public static function classToSnakeCase($class, $trim = null)
13
    {
14 6
        $reflect = new \ReflectionClass($class);
15 6
        $name = $reflect->getShortName();
16 6
        if (!is_null($trim)) {
17 5
            $name = str_replace($trim, '', $name);
18 5
        }
19
20 6
        return ltrim(strtolower(preg_replace('/[A-Z]/', '_$0', $name)), '_');
21
    }
22
}
23