InflectsString   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toCamelCase() 0 7 1
A toWords() 0 5 1
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