Completed
Push — master ( 39c07f...aa04c1 )
by Jitendra
11s
created

Inflector::snakeCase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Ahc\Phint\Util;
4
5
class Inflector
6
{
7
    /**
8
     * StuldyCase.
9
     *
10
     * @param string $path
11
     *
12
     * @return string
13
     */
14
    public function stuldyCase(string $string): string
15
    {
16
        return str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $string)));
17
    }
18
19
    /**
20
     * Separate words.
21
     *
22
     * @param string $path
23
     *
24
     * @return string
25
     */
26
    public function words(string $string): string
27
    {
28
        return ucwords(str_replace(['-', '_'], ' ', $string));
29
    }
30
31
    /**
32
     * Snakeize.
33
     *
34
     * @param string $path
35
     *
36
     * @return string
37
     */
38
    public function snakeCase(string $string): string
39
    {
40
        $string = \str_replace([' ', '-'], '_', $string);
41
42
        return \ltrim(\strtolower(\preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '_$0', $string)), '_');
43
    }
44
}
45