InflectsString::toWords()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
/*
4
 * This file is part of the PHP-CLI package.
5
 *
6
 * (c) Jitendra Adhikari <[email protected]>
7
 *     <https://github.com/adhocore>
8
 *
9
 * Licensed under MIT license.
10
 */
11
12
namespace Ahc\Cli\Helper;
13
14
/**
15
 * Performs inflection on strings.
16
 *
17
 * @author  Jitendra Adhikari <[email protected]>
18
 * @license MIT
19
 *
20
 * @link    https://github.com/adhocore/cli
21
 */
22
trait InflectsString
23
{
24
    /**
25
     * Convert a string to camel case.
26
     *
27
     * @param string $string
28
     *
29
     * @return string
30
     */
31
    public function toCamelCase(string $string): string
32
    {
33
        $words = \str_replace(['-', '_'], ' ', $string);
34
35
        $words = \str_replace(' ', '', \ucwords($words));
36
37
        return \lcfirst($words);
38
    }
39
40
    /**
41
     * Convert a string to capitalized words.
42
     *
43
     * @param string $string
44
     *
45
     * @return string
46
     */
47
    public function toWords(string $string): string
48
    {
49
        $words = \trim(\str_replace(['-', '_'], ' ', $string));
50
51
        return \ucwords($words);
52
    }
53
}
54