InflectionUnderscoreTrait::doUnderscore()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
nc 1
nop 1
dl 0
loc 13
ccs 11
cts 11
cp 1
crap 1
rs 9.9
c 1
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
                        $word
31
                    )
32
                )
33
            )
34
        );
35
    }
36
}
37