Inflector::humanize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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