Passed
Push — master ( 03087a...f49b8e )
by Gabriel
01:58
created

InflectionUnderscoreTrait::doUnderscore()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 1
dl 0
loc 18
ccs 12
cts 12
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Nip\Inflector\Traits;
4
5
/**
6
 * Trait InflectionUnderscoreTrait
7
 * @package Nip\Inflector\Traits
8
 *
9
 * @method underscore($string)
10
 */
11
trait InflectionUnderscoreTrait
12
{
13
14
    /**
15
     * @param $word
16
     * @return string
17
     */
18 5
    protected function doUnderscore($word)
19
    {
20 5
        return strtolower(
21 5
            preg_replace(
22 5
                '/[^A-Z^a-z^0-9]+/',
23 5
                '_',
24 5
                preg_replace(
25 5
                    '/([a-zd])([A-Z])/',
26 5
                    '\1_\2',
27 5
                    preg_replace(
28 5
                        '/([A-Z]+)([A-Z][a-z])/',
29 5
                        '\1_\2',
30 5
                        $word
31
                    )
32
                )
33
            )
34
        );
35
    }
36
}
37