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

InflectionUnderscoreTrait   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A doUnderscore() 0 18 1
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