Inflector   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 2 Features 0
Metric Value
wmc 5
c 5
b 2
f 0
lcom 1
cbo 0
dl 0
loc 51
ccs 13
cts 13
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A humanize() 0 4 1
A title() 0 4 1
A titlecase() 0 4 1
A initials() 0 12 2
1
<?php
2
3
namespace CL\ComposerInit;
4
5
class Inflector
6
{
7
    /**
8
     * Makes an underscored or dashed phrase human-readable.
9
     *
10
     *     $string = $inflector->humanize('kittens-are-cats'); // "kittens are cats"
11
     *     $string = $inflector->humanize('dogs_as_well');     // "dogs as well"
12
     *
13
     * @param  string $string phrase to make human-readable
14
     * @return string
15
     */
16 2
    public function humanize($string)
17
    {
18 2
        return preg_replace('/[_-]+/', ' ', trim($string));
19
    }
20
21
    /**
22
     * @param  string $string
23
     * @return string
24
     */
25 2
    public function title($string)
26
    {
27 2
        return ucwords($this->humanize($string));
28
    }
29
30
    /**
31
     * @param  string $string
32
     * @return string
33
     */
34 2
    public function titlecase($string)
35
    {
36 2
        return str_replace(' ', '', $this->title($string));
37
    }
38
39
    /**
40
     * @param  string $string
41
     * @return string
42
     */
43 3
    public function initials($string)
44
    {
45 3
        $title = $this->title($string);
46
47 3
        $initials = str_replace(' ', '', preg_replace('/[a-z]/', '', $title));
48
49 3
        if (mb_strlen($initials) == 1) {
50 2
            $initials .= mb_strtoupper($title[1]);
51 2
        }
52
53 3
        return $initials;
54
    }
55
}
56