Completed
Push — master ( aafc8c...73adad )
by Jitendra
11s
created

InflectsString::toWords()   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\Cli\Helper;
4
5
/**
6
 * Performs inflection on strings.
7
 *
8
 * @author  Jitendra Adhikari <[email protected]>
9
 * @license MIT
10
 *
11
 * @link    https://github.com/adhocore/cli
12
 */
13
trait InflectsString
14
{
15
    /**
16
     * Convert a string to camel case.
17
     *
18
     * @param string $string
19
     *
20
     * @return string
21
     */
22
    public function toCamelCase(string $string): string
23
    {
24
        $words = \str_replace(['-', '_'], ' ', $string);
25
26
        $words = \str_replace(' ', '', \ucwords($words));
27
28
        return \lcfirst($words);
29
    }
30
31
    /**
32
     * Convert a string to capitalized words.
33
     *
34
     * @param string $string
35
     *
36
     * @return string
37
     */
38
    public function toWords(string $string): string
39
    {
40
        $words = \trim(\str_replace(['-', '_'], ' ', $string));
41
42
        return \ucwords($words);
43
    }
44
}
45