Passed
Push — master ( 7d2fba...2be253 )
by Jean Paul
01:17
created

TextUtils   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A textToCamelCase() 0 16 1
A textToPascalCase() 0 13 1
1
<?php
2
3
namespace Coco\SourceWatcher\Utils;
4
5
/**
6
 * Class TextUtils
7
 * @package Coco\SourceWatcher\Utils
8
 */
9
class TextUtils
10
{
11
    /**
12
     * @param string $word
13
     * @return string
14
     */
15
    public function textToCamelCase ( string $word ) : string
16
    {
17
        // Make an array of word parts exploding the word by "_"
18
        $wordParts = explode( "_", $word );
19
20
        // Make every word part lower case
21
        $wordParts = array_map( "strtolower", $wordParts );
22
23
        // Make every word part first character uppercase
24
        $wordParts = array_map( "ucfirst", $wordParts );
25
26
        // Make the new word the combination of the given word parts
27
        $newWord = implode( "", $wordParts );
28
29
        // Make the new word first character lowercase
30
        return lcfirst( $newWord );
31
    }
32
33
    /**
34
     * @param string $word
35
     * @return string
36
     */
37
    public function textToPascalCase ( string $word ) : string
38
    {
39
        // Make an array of word parts exploding the word by "_"
40
        $wordParts = explode( "_", $word );
41
42
        // Make every word part lower case
43
        $wordParts = array_map( "strtolower", $wordParts );
44
45
        // Make every word part first character uppercase
46
        $wordParts = array_map( "ucfirst", $wordParts );
47
48
        // Make the new word the combination of the given word parts
49
        return implode( "", $wordParts );
50
    }
51
}
52